all repos — homestead @ 02344e6cb41515516464de403e2eae1caac81e5c

Code for my website

switch from templ to gomponent

Alan Pearce
commit

02344e6cb41515516464de403e2eae1caac81e5c

parent

4034ac2a849b499364d82b902896ca899d946c3a

1 file changed, 63 insertions(+), 0 deletions(-)

changed files
A templates/post.go
@@ -0,0 +1,63 @@
+package templates + +import ( + "time" + + "go.alanpearce.eu/homestead/internal/content" + + g "maragu.dev/gomponents" + . "maragu.dev/gomponents/html" +) + +func PostPage(site SiteSettings, post *content.Post) g.Node { + return Layout(site, PageSettings{ + Title: post.Title, + TitleAttrs: g.Group([]g.Node{Class("p-author h-card"), Rel("author")}), + BodyAttrs: Class("h-entry"), + }, Article( + Header( + H1(Class("p-name"), g.Text(post.Title)), + P(Class("meta"), + Span(Class("date"), + g.Text("Published: "), + A(Class("u-url"), Href(post.URL), postDate(post.Date, "dt-published")), + ), + g.Iff(len(post.Commits) > 1, lastUpdated(post)), + ), + ), + Div(Class("e-content"), + post, + ), + Div(Class("tags"), + g.Text("Tags: "), + Ul(Class("p-categories tags"), + g.Map(post.Taxonomies.Tags, func(tag string) g.Node { + return Li( + tagLink(tag, Class("p-category")), + ) + }), + ), + ), + )) +} + +func postDate(d time.Time, class string) g.Node { + return Time( + Class(class), + DateTime(d.UTC().Format(time.RFC3339)), + g.Text(d.Format("2006-01-02")), + ) +} + +func lastUpdated(post *content.Post) func() g.Node { + return func() g.Node { + return Span( + Class("date last-updated"), + g.Text("Last updated: "), + A( + Href(post.Commits[0].Link.String()), + postDate(post.Commits[0].Date, "dt-updated"), + ), + ) + } +}