Compare commits
No commits in common. "6a17f7ed45c6e77abffcce675f328d426bc9079f" and "1981a291aa6acb935569a16ac68f91654507f813" have entirely different histories.
6a17f7ed45
...
1981a291aa
2 changed files with 9 additions and 6 deletions
|
@ -13,6 +13,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/aymerick/raymond"
|
||||||
"github.com/mitchellh/mapstructure"
|
"github.com/mitchellh/mapstructure"
|
||||||
"github.com/yuin/goldmark"
|
"github.com/yuin/goldmark"
|
||||||
emoji "github.com/yuin/goldmark-emoji"
|
emoji "github.com/yuin/goldmark-emoji"
|
||||||
|
@ -39,6 +40,10 @@ type Post struct {
|
||||||
Image []byte
|
Image []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *Post) Render(tpl *raymond.Template) (string, error) {
|
||||||
|
return tpl.Exec(p)
|
||||||
|
}
|
||||||
|
|
||||||
func (p *Post) String() string {
|
func (p *Post) String() string {
|
||||||
return p.Slug
|
return p.Slug
|
||||||
}
|
}
|
||||||
|
@ -166,9 +171,7 @@ func (pl *postList) fetchLocked(filename string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer func() {
|
defer slices.SortFunc(pl.posts, postLess)
|
||||||
slices.SortFunc(pl.posts, postLess)
|
|
||||||
}()
|
|
||||||
for i, post := range pl.posts {
|
for i, post := range pl.posts {
|
||||||
if post.Slug == p.Slug {
|
if post.Slug == p.Slug {
|
||||||
pl.posts[i] = p
|
pl.posts[i] = p
|
||||||
|
|
|
@ -95,7 +95,7 @@ func (s *server) serveGetPost(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
w.Header().Add("content-type", "text/html; charset=utf-8")
|
w.Header().Add("content-type", "text/html; charset=utf-8")
|
||||||
tpl, _ := s.templates.Get("fullpost.html")
|
tpl, _ := s.templates.Get("fullpost.html")
|
||||||
contents, err := tpl.Exec(p)
|
contents, err := p.Render(tpl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.errorInRequest(w, r, err)
|
s.errorInRequest(w, r, err)
|
||||||
return
|
return
|
||||||
|
@ -115,7 +115,7 @@ func (s *server) serveGetHome(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
summaryTpl, _ := s.templates.Get("summary.html")
|
summaryTpl, _ := s.templates.Get("summary.html")
|
||||||
for _, p := range s.posts.All() {
|
for _, p := range s.posts.All() {
|
||||||
summary, err := summaryTpl.Exec(p)
|
summary, err := p.Render(summaryTpl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("could not render post summary for %s", p.Slug)
|
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 != "" {
|
if pubDate != "" {
|
||||||
pubDate = common.RSSDatetime(p.Metadata.Time)
|
pubDate = common.RSSDatetime(p.Metadata.Time)
|
||||||
}
|
}
|
||||||
summary, err := rssItemTpl.Exec(p)
|
summary, err := p.Render(rssItemTpl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("could not render post summary for %s", p.Slug)
|
log.Printf("could not render post summary for %s", p.Slug)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue