From e2dd1afaa3b342aa976b17eee344faf670e03307 Mon Sep 17 00:00:00 2001 From: Naman Sood Date: Fri, 29 Nov 2024 08:02:26 -0500 Subject: [PATCH 1/2] remove Post.Render Signed-off-by: Naman Sood --- postmap/postmap.go | 5 ----- server/server.go | 6 +++--- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/postmap/postmap.go b/postmap/postmap.go index 0657e06..93f24d2 100644 --- a/postmap/postmap.go +++ b/postmap/postmap.go @@ -13,7 +13,6 @@ import ( "strings" "sync" - "github.com/aymerick/raymond" "github.com/mitchellh/mapstructure" "github.com/yuin/goldmark" emoji "github.com/yuin/goldmark-emoji" @@ -40,10 +39,6 @@ type Post struct { Image []byte } -func (p *Post) Render(tpl *raymond.Template) (string, error) { - return tpl.Exec(p) -} - func (p *Post) String() string { return p.Slug } diff --git a/server/server.go b/server/server.go index 03ccfa0..c582d10 100644 --- a/server/server.go +++ b/server/server.go @@ -95,7 +95,7 @@ func (s *server) serveGetPost(w http.ResponseWriter, r *http.Request) { } w.Header().Add("content-type", "text/html; charset=utf-8") tpl, _ := s.templates.Get("fullpost.html") - contents, err := p.Render(tpl) + contents, err := tpl.Exec(p) if err != nil { s.errorInRequest(w, r, err) return @@ -115,7 +115,7 @@ func (s *server) serveGetHome(w http.ResponseWriter, r *http.Request) { summaryTpl, _ := s.templates.Get("summary.html") for _, p := range s.posts.All() { - summary, err := p.Render(summaryTpl) + summary, err := summaryTpl.Exec(p) if err != nil { log.Printf("could not render post summary for %s", p.Slug) } @@ -163,7 +163,7 @@ func (s *server) serveGetRSS(w http.ResponseWriter, r *http.Request) { if pubDate != "" { pubDate = common.RSSDatetime(p.Metadata.Time) } - summary, err := p.Render(rssItemTpl) + summary, err := rssItemTpl.Exec(p) if err != nil { log.Printf("could not render post summary for %s", p.Slug) } From 6a17f7ed45c6e77abffcce675f328d426bc9079f Mon Sep 17 00:00:00 2001 From: Naman Sood Date: Fri, 29 Nov 2024 08:02:43 -0500 Subject: [PATCH 2/2] fix bug in post sorting Signed-off-by: Naman Sood --- postmap/postmap.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/postmap/postmap.go b/postmap/postmap.go index 93f24d2..a7e0106 100644 --- a/postmap/postmap.go +++ b/postmap/postmap.go @@ -166,7 +166,9 @@ func (pl *postList) fetchLocked(filename string) error { if err != nil { return err } - defer slices.SortFunc(pl.posts, postLess) + defer func() { + slices.SortFunc(pl.posts, postLess) + }() for i, post := range pl.posts { if post.Slug == p.Slug { pl.posts[i] = p