package templates
import (
"time"
"alin.ovh/homestead/domain/content"
"alin.ovh/homestead/domain/web/templates"
"alin.ovh/homestead/shared/vcs"
g "alin.ovh/gomponents"
. "alin.ovh/gomponents/html"
)
func PostPage(site templates.SiteSettings, post *content.Post) g.Node {
return templates.Layout(site, templates.PageSettings{
Title: post.Title,
TitleAttrs: templates.Attrs{"class": "p-author h-card", "rel": "author"},
BodyAttrs: templates.Attrs{"class": "h-entry"},
}, Article(
Header(
HGroup(
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"),
),
)
}
}
domain/content/templates/post.go (view raw)