From e1f6b6b8f3465b4819364efc497fea6d9ddad67e Mon Sep 17 00:00:00 2001 From: Leonardo Bishop Date: Thu, 17 Jul 2025 22:36:19 +0100 Subject: Implement disabled flag --- pkg/html/notfound.go | 25 ------------------------- pkg/html/status.go | 33 +++++++++++++++++++++++++++++++++ pkg/site/fs.go | 5 +++++ 3 files changed, 38 insertions(+), 25 deletions(-) delete mode 100644 pkg/html/notfound.go create mode 100644 pkg/html/status.go (limited to 'pkg') diff --git a/pkg/html/notfound.go b/pkg/html/notfound.go deleted file mode 100644 index ceb521f..0000000 --- a/pkg/html/notfound.go +++ /dev/null @@ -1,25 +0,0 @@ -package html - -import ( - "fmt" - - . "github.com/LMBishop/scrapbook/web/skeleton" - . "maragu.dev/gomponents" - . "maragu.dev/gomponents/html" -) - -func NotFoundUrlPage(url, host string) Node { - return Page("Page not found", - H1(Text("Page not found")), - - P(Text(fmt.Sprintf("The URL %s could not be found on site %s", url, host))), - ) -} - -func NotFoundSitePage(host string) Node { - return Page("Site not found", - H1(Text("Site not found")), - - P(Text(fmt.Sprintf("The site %s is unknown", host))), - ) -} diff --git a/pkg/html/status.go b/pkg/html/status.go new file mode 100644 index 0000000..569a236 --- /dev/null +++ b/pkg/html/status.go @@ -0,0 +1,33 @@ +package html + +import ( + "fmt" + + . "github.com/LMBishop/scrapbook/web/skeleton" + . "maragu.dev/gomponents" + . "maragu.dev/gomponents/html" +) + +func NotFoundUrlPage(url, host string) Node { + return Page("Page not found", + H1(Text("Page not found")), + + P(Text(fmt.Sprintf("The URL %s could not be found on site %s", url, host))), + ) +} + +func NotFoundSitePage(host string) Node { + return Page("Site not found", + H1(Text("Site not found")), + + P(Text(fmt.Sprintf("The site %s is unknown", host))), + ) +} + +func ForbiddenDisabledPage(host string) Node { + return Page("Forbidden", + H1(Text("Forbidden")), + + P(Text(fmt.Sprintf("Site %s is disabled", host))), + ) +} diff --git a/pkg/site/fs.go b/pkg/site/fs.go index c9bbe21..b4a941d 100644 --- a/pkg/site/fs.go +++ b/pkg/site/fs.go @@ -21,6 +21,11 @@ func NewSiteFileServer(root http.FileSystem, siteConfig *config.SiteConfig) *Sit } func (fs *SiteFileServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { + if fs.siteConfig.Flags&config.FlagDisable != 0 { + html.ForbiddenDisabledPage(fs.siteConfig.Host).Render(w) + return + } + path := filepath.Clean(r.URL.Path) file, err := fs.root.Open(path) -- cgit v1.2.3-70-g09d2