diff options
Diffstat (limited to 'web/command/handler/site.go')
| -rw-r--r-- | web/command/handler/site.go | 27 |
1 files changed, 27 insertions, 0 deletions
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 + }) +} |
