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 25, 2024
1 parent 47366fe commit 7ef603e
Show file tree
Hide file tree
Showing 4 changed files with 309 additions and 285 deletions.
16 changes: 3 additions & 13 deletions internal/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (a *Application) Start() {
noArgs := func(r *http.Request) map[string]any { return nil }

// Static pages
staticPages2 := map[string]struct {
staticPages := map[string]struct {
title string
pageName partials.PageName
content templ.Component
Expand All @@ -120,8 +120,9 @@ func (a *Application) Start() {
"GET /rules": {"Rules", partials.PageNameRules, templates.Rules()},
"GET /register": {"Register", partials.PageNameRegister, templates.Register()},
"GET /faq": {"FAQ", partials.PageNameFAQ, templates.FAQ()},
"GET /archive": {"Archive", partials.PageNameArchive, templates.Archive(archiveInfo)},
}
for path, pageInfo := range staticPages2 {
for path, pageInfo := range staticPages {
router.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
user, err := a.GetLoggedInTeacher(r)
Expand All @@ -136,17 +137,6 @@ func (a *Application) Start() {
})
}

// Static pages
staticPages := map[string]struct {
Template string
ArgGenerator func(r *http.Request) map[string]any
}{
"/archive": {"archive.html", a.GetArchiveTemplate},
}
for path, templateInfo := range staticPages {
router.HandleFunc("GET "+path, a.ServeTemplate(a.Log, templateInfo.Template, templateInfo.ArgGenerator))
}

// Redirect pages
redirects := map[string]string{
"/register/teacher": "/register/teacher/createaccount",
Expand Down
Loading

0 comments on commit 7ef603e

Please sign in to comment.