From cdb75d3fcbc9339b897f8c6ff4d69a577f017393 Mon Sep 17 00:00:00 2001 From: Leonardo Bishop Date: Tue, 8 Jul 2025 23:26:05 +0100 Subject: Rewrite in Go --- web/command/handler/site.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 web/command/handler/site.go (limited to 'web/command/handler/site.go') diff --git a/web/command/handler/site.go b/web/command/handler/site.go new file mode 100644 index 0000000..73ea1a0 --- /dev/null +++ b/web/command/handler/site.go @@ -0,0 +1,27 @@ +package handler + +import ( + "fmt" + "net/http" + + "github.com/LMBishop/scrapbook/pkg/config" + "github.com/LMBishop/scrapbook/pkg/index" + "github.com/LMBishop/scrapbook/web/command/html" + . "maragu.dev/gomponents" + ghttp "maragu.dev/gomponents/http" +) + +func GetSite(mainConfig *config.MainConfig, index *index.SiteIndex) func(http.ResponseWriter, *http.Request) { + return ghttp.Adapt(func(w http.ResponseWriter, r *http.Request) (Node, error) { + siteName := r.PathValue("site") + if siteName == "" { + return nil, fmt.Errorf("unknown site") + } + site := index.GetSite(siteName) + if site == nil { + return nil, fmt.Errorf("unknown site") + } + + return html.SitePage(mainConfig, site), nil + }) +} -- cgit v1.2.3-70-g09d2