all repos — homestead @ e92c0deb48827d72ac36cb8280bf7dec757b248a

Code for my website

templates/list.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
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: Attrs{"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: Attrs{"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)),
		)
	}))
}