From e338880609e5d0181c52c57352e769494244cbdf Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Thu, 15 Aug 2024 18:00:13 -0400 Subject: [PATCH] Correctly show 404 page on /sitemap.xml on multi-user instances Sitemaps are only meant for individual blogs right now, so instead of invalid HTML getting returned, we'll properly catch the issue and show a user-friendly "not found" page. Fixes #941 --- posts.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/posts.go b/posts.go index 46f5871..f31f5da 100644 --- a/posts.go +++ b/posts.go @@ -314,6 +314,8 @@ func handleViewPost(app *App, w http.ResponseWriter, r *http.Request) error { // Display reserved page if that is requested resource if t, ok := pages[r.URL.Path[1:]+".tmpl"]; ok { return handleTemplatedPage(app, w, r, t) + } else if r.URL.Path == "/sitemap.xml" && !app.cfg.App.SingleUser { + return impart.HTTPError{Status: http.StatusNotFound, Message: "Page not found."} } else if (strings.Contains(r.URL.Path, ".") && !isRaw && !isMarkdown) || r.URL.Path == "/robots.txt" || r.URL.Path == "/manifest.json" { // Serve static file app.shttp.ServeHTTP(w, r)