all repos — homestead @ 02344e6cb41515516464de403e2eae1caac81e5c

Code for my website

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
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"),
			),
		)
	}
}