all repos — homestead @ f7d8beffaa09ecf863996d29c72f508eb3952c84

Code for my website

domain/content/templates/list.go (view raw)

package templates

import (
	g "alin.ovh/gomponents"
	. "alin.ovh/gomponents/html"

	"alin.ovh/homestead/domain/content"
	"alin.ovh/homestead/domain/web/templates"
)

type TagPageVars struct {
	Tag   string
	Posts []*content.Post
}

type ListPageVars struct {
	Posts []*content.Post
}

func TagPage(site templates.SiteSettings, vars TagPageVars) g.Node {
	return templates.Layout(site, templates.PageSettings{
		Title:      vars.Tag,
		TitleAttrs: templates.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),
	))
}

func ListPage(site templates.SiteSettings, vars ListPageVars) g.Node {
	return templates.Layout(site, templates.PageSettings{
		Title:      site.Title,
		TitleAttrs: templates.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)),
		)
	}))
}