Skip to content

Commit

Permalink
Exposed server sitemap.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kugelschieber committed Jun 4, 2024
1 parent af2b62f commit fe3af30
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.7.0

* exposed server sitemap

## 0.6.2

* fixed router setup
Expand Down
17 changes: 10 additions & 7 deletions pkg/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(),
Expand All @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion pkg/version.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package pkg

const (
version = "0.6.2"
version = "0.7.0"
)

// Version returns the Shifu version number.
Expand Down

0 comments on commit fe3af30

Please sign in to comment.