all repos — homestead @ 02344e6cb41515516464de403e2eae1caac81e5c

Code for my website

switch from templ to gomponent

Alan Pearce
commit

02344e6cb41515516464de403e2eae1caac81e5c

parent

4034ac2a849b499364d82b902896ca899d946c3a

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

changed files
A templates/list.go
@@ -0,0 +1,56 @@
+package templates + +import ( + "go.alanpearce.eu/homestead/internal/content" + + g "maragu.dev/gomponents" + . "maragu.dev/gomponents/html" +) + +type TagPageVars struct { + Tag string + Posts []*content.Post +} + +func TagPage(site SiteSettings, vars TagPageVars) g.Node { + return Layout(site, PageSettings{ + Title: vars.Tag, + TitleAttrs: Class("p-author h-card"), + }, Div( + ID("content"), + Div(Class("filter"), + H3(Class("filter"), g.Text(vars.Tag)), + Small( + A(Href("../"), g.Text("Remove filter")), + ), + ), + list(vars.Posts), + )) +} + +type ListPageVars struct { + Posts []*content.Post +} + +func ListPage(site SiteSettings, vars ListPageVars) g.Node { + return Layout(site, PageSettings{ + Title: site.Title, + TitleAttrs: Class("p-author h-card"), + }, + Div( + ID("content"), + list(vars.Posts), + ), + ) +} + +func list(posts []*content.Post) g.Node { + return Ul(Class("h-feed"), g.Map(posts, func(post *content.Post) g.Node { + return Li(Class("h-entry"), + Span( + postDate(post.Date, "dt-published"), + ), + A(Class("p-name u-url"), Href(post.URL), g.Text(post.Title)), + ) + })) +}