From 3b9d034680846addd776e3ac69829c0904dac3c1 Mon Sep 17 00:00:00 2001 From: Sumner Evans Date: Sun, 26 May 2024 08:54:23 -0600 Subject: [PATCH] fixup! templates: render static pages using templ Signed-off-by: Sumner Evans --- internal/application.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/internal/application.go b/internal/application.go index 6f27831..139392b 100644 --- a/internal/application.go +++ b/internal/application.go @@ -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