diff options
| author | Rose Hogenson <rosehogenson@posteo.net> | 2024-10-22 21:20:55 -0700 |
|---|---|---|
| committer | Rose Hogenson <rosehogenson@posteo.net> | 2024-10-22 21:20:55 -0700 |
| commit | 59f10197ee75a881213ac50fbb026601f027bbe4 (patch) | |
| tree | a16c14072a0c7d21569229b7fba712172ee4846c /roseh.moe.go | |
| parent | Write a blog post. (diff) | |
| download | roseh.moe-59f10197ee75a881213ac50fbb026601f027bbe4.tar.zst | |
Fix some bugs in how blog posts are rendered.
Diffstat (limited to 'roseh.moe.go')
| -rw-r--r-- | roseh.moe.go | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/roseh.moe.go b/roseh.moe.go index ad09cb5..f159692 100644 --- a/roseh.moe.go +++ b/roseh.moe.go @@ -23,10 +23,12 @@ var ( serverStartTime = time.Now() ) -//go:embed templates/404.html.template -var notFoundString string +var ( + //go:embed templates/404.html.template + notFoundString string -var notFoundTemplate = template.Must(template.New("notFound").Parse(notFoundString)) + notFoundTemplate = template.Must(template.New("notFound").Parse(notFoundString)) +) func notFound(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusNotFound) @@ -38,10 +40,12 @@ func notFound(w http.ResponseWriter, r *http.Request) { } } -//go:embed templates/outline.html.template -var outlineString string +var ( + //go:embed templates/outline.html.template + outlineString string -var outlineTemplate = template.Must(template.New("outline").Parse(outlineString)) + outlineTemplate = template.Must(template.New("outline").Parse(outlineString)) +) var ( //go:embed templates/blog/post.html.template @@ -66,7 +70,7 @@ func preloadBlogPosts() map[string][]byte { } posts := make(map[string][]byte, len(postTemplates)) for _, post := range postTemplates { - base, err = base.Clone() + postTemplate, err := base.Clone() if err != nil { log.Fatalf("base.Clone: %s", err) } @@ -74,7 +78,7 @@ func preloadBlogPosts() map[string][]byte { if err != nil { log.Fatalf("somehow I fucked the paths up: %s", err) } - postTemplate, err := base.New("post").Parse(string(postString)) + postTemplate, err = postTemplate.New("post").Parse(string(postString)) if err != nil { log.Fatalf("%q: invalid template: %s", post.Name(), err) } @@ -125,7 +129,7 @@ func preloadIndex() []byte { for p := range blogPostsHTML { posts = append(posts, p) } - slices.Sort(posts) + slices.SortFunc(posts, func(x, y string) int { return strings.Compare(y, x) }) buf := new(bytes.Buffer) if err := indexTemplate.ExecuteTemplate(buf, "outline", posts); err != nil { log.Fatalf("index.html.template: error: %s", err) |
