templates/post.go (view raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | package templates import ( "time" "go.alanpearce.eu/homestead/internal/content" "go.alanpearce.eu/homestead/internal/vcs" g "go.alanpearce.eu/gomponents" . "go.alanpearce.eu/gomponents/html" ) func PostPage(site SiteSettings, post *content.Post) g.Node { return Layout(site, PageSettings{ Title: post.Title, TitleAttrs: Attrs{"class": "p-author h-card", "rel": "author"}, BodyAttrs: Attrs{"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, ), g.If(len(post.Taxonomies.Tags) > 0, 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")), ) }), ), ), ), g.If(len(post.Commits) > 1, Details(Class("changelog"), Summary(g.Text("Changelog")), Ul( g.Map(post.Commits, func(commit *vcs.Commit) g.Node { return Li( TitleAttr(commit.Description), postDate(commit.Date, ""), g.Text(" "), A( Href(commit.MakeFileLink(post.Input).String()), g.Text(commit.Summary), ), g.Text(" "), g.If( len(commit.Description) > 0, Small( g.Text(" …"), ), ), ) }), ), ), ), )) } 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].MakeFileLink(post.Input).String()), postDate(post.Commits[0].Date, "dt-updated"), ), ) } } |