Skip to content

Commit

Permalink
fixup! templates: render static pages using templ
Browse files Browse the repository at this point in the history
Signed-off-by: Sumner Evans <me@sumnerevans.com>
  • Loading branch information
sumnerevans committed May 26, 2024
1 parent 3f6db8c commit 3b9d034
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions internal/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,14 @@ func (a *Application) Start() {
"GET /archive/": {"Archive", partials.PageNameArchive, templates.Archive(archiveInfo)},
}
for path, pageInfo := range staticPages {
router.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
if len(pageInfo.pageName) > 0 {
ctx = context.WithValue(ctx, contextkeys.ContextKeyPageName, pageInfo.pageName)
}
templates.Base(pageInfo.title, pageInfo.content).Render(ctx, w)
})
if len(pageInfo.pageName) == 0 {
router.Handle(path, templ.Handler(templates.Base(pageInfo.title, pageInfo.content)))
} else {
router.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
ctx := context.WithValue(r.Context(), contextkeys.ContextKeyPageName, pageInfo.pageName)
templates.Base(pageInfo.title, pageInfo.content).Render(ctx, w)
})
}
}

// Redirect pages
Expand Down

0 comments on commit 3b9d034

Please sign in to comment.