Skip to content

Commit

Permalink
Fix new pages being created as "Page not found"
Browse files Browse the repository at this point in the history
  • Loading branch information
greboid committed Apr 2, 2021
1 parent 273b9c1 commit bb40862
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ type RenderPageArgs struct {
type ErrorPageArgs struct {
CommonPageArgs
ShowLoginForm bool
OldPageTitle string
}

type RenamePageArgs struct {
Expand Down
9 changes: 8 additions & 1 deletion middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,10 @@ func PageErrorHandler(templateFs fs.FS) func(http.Handler) http.Handler {
if strings.HasPrefix(r.RequestURI, "/view/") || strings.HasPrefix(r.RequestURI, "/history") {
isWiki = true
}

oldPageTitle := ""
if strings.HasPrefix(r.RequestURI, "/view/") {
oldPageTitle = strings.TrimPrefix(r.RequestURI, "/view/")
}
renderTemplate(templateFs, NotFound, http.StatusNotFound, w, &ErrorPageArgs{
CommonPageArgs{
Session: getSessionArgs(w, r),
Expand All @@ -221,6 +224,7 @@ func PageErrorHandler(templateFs fs.FS) func(http.Handler) http.Handler {
IsError: true,
},
false,
oldPageTitle,
})
}
if fakeWriter.status == http.StatusUnauthorized {
Expand All @@ -231,6 +235,7 @@ func PageErrorHandler(templateFs fs.FS) func(http.Handler) http.Handler {
IsError: true,
},
true,
"",
})
}
if fakeWriter.status == http.StatusForbidden {
Expand All @@ -241,6 +246,7 @@ func PageErrorHandler(templateFs fs.FS) func(http.Handler) http.Handler {
IsError: true,
},
false,
"",
})
}
if fakeWriter.status == http.StatusInternalServerError {
Expand All @@ -251,6 +257,7 @@ func PageErrorHandler(templateFs fs.FS) func(http.Handler) http.Handler {
IsError: true,
},
false,
"",
})
}
})
Expand Down
4 changes: 2 additions & 2 deletions templates/404.gohtml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{- /*gotype: github.com/mdbot/wiki.NotFoundPageArgs*/ -}}
{{- /*gotype: github.com/mdbot/wiki.ErrorPageArgs*/ -}}
{{template "header" .CommonPageArgs}}
<h1>Page not found</h1>
{{if and .CommonPageArgs.IsWikiPage .CommonPageArgs.Session.CanEdit}}
<p><a href="/edit/{{.PageTitle}}">Create it</a></p>
<p><a href="/edit/{{.OldPageTitle}}">Create it</a></p>
{{end}}
{{template "footer" .CommonPageArgs}}

0 comments on commit bb40862

Please sign in to comment.