From fe3af30818bf60f312a034972933645a494305a1 Mon Sep 17 00:00:00 2001 From: Marvin Blum Date: Tue, 4 Jun 2024 20:38:08 +0200 Subject: [PATCH] Exposed server sitemap. --- CHANGELOG.md | 4 ++++ pkg/server.go | 17 ++++++++++------- pkg/version.go | 2 +- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a74a01..c0fea8b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 0.7.0 + +* exposed server sitemap + ## 0.6.2 * fixed router setup diff --git a/pkg/server.go b/pkg/server.go index a8a182f..f2c3ff5 100644 --- a/pkg/server.go +++ b/pkg/server.go @@ -39,6 +39,9 @@ type Server struct { // Content is the CMS content. Content *cms.CMS + // Sitemap is the sitemap generated from the content. + Sitemap *sitemap.Sitemap + router chi.Router dir string funcMap template.FuncMap @@ -98,22 +101,22 @@ func (server *Server) Start(cancel context.CancelFunc) error { return errors.New("content provider not found") } - sm := sitemap.New() + server.Sitemap = sitemap.New() server.Content = cms.NewCMS(cms.Options{ Ctx: ctx, BaseDir: server.dir, HotReload: cfg.Get().Dev, FuncMap: server.funcMap, Source: provider, - Sitemap: sm, + Sitemap: server.Sitemap, }) analytics.Init() - server.setupRouter(server.dir, server.Content, sm) + server.setupRouter() <-server.startServer(server.router, stop) return nil } -func (server *Server) setupRouter(dir string, cms *cms.CMS, sm *sitemap.Sitemap) { +func (server *Server) setupRouter() { router := chi.NewRouter() router.Use( middleware.Cors(), @@ -134,10 +137,10 @@ func (server *Server) setupRouter(dir string, cms *cms.CMS, sm *sitemap.Sitemap) } } - sm.Serve(router) + server.Sitemap.Serve(router) server.serveRobotsTxt(router) - server.serveStaticDir(router, dir) - router.Handle("/*", http.HandlerFunc(cms.Serve)) + server.serveStaticDir(router, server.dir) + router.Handle("/*", http.HandlerFunc(server.Content.Serve)) server.router = router for _, route := range router.Routes() { diff --git a/pkg/version.go b/pkg/version.go index 70887fc..c6b7cdb 100644 --- a/pkg/version.go +++ b/pkg/version.go @@ -1,7 +1,7 @@ package pkg const ( - version = "0.6.2" + version = "0.7.0" ) // Version returns the Shifu version number.