all repos — homestead @ 431e351c78000ccd0d6bf035b4cd1092a7744d85

Code for my website

templates/post.templ (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
package templates

import (
	"context"
	"io"
	"time"

	"go.alanpearce.eu/website/internal/config"
	"go.alanpearce.eu/website/internal/content"
)

func Unsafe(html string) templ.Component {
	return templ.ComponentFunc(func(ctx context.Context, w io.Writer) (err error) {
		_, err = io.WriteString(w, html)
		return
	})
}

templ postDate(d time.Time, class string) {
	<time class={ class } datetime={ d.UTC().Format(time.RFC3339) }>
		{ d.Format("2006-01-02") }
	</time>
}

templ PostPage(config *config.Config, post content.Post) {
	@Layout(config, PageSettings{
		Title: post.Title,
		TitleAttrs: templ.Attributes{
			"class": "p-author h-card",
			"rel":   "author",
		},
		BodyAttrs: templ.Attributes{
			"class": "h-entry",
		},
		Path: post.URL,
	}) {
		<article>
			<header>
				<h1 class="p-name">{ post.Title }</h1>
				<p class="meta">
					<span class="date">
						Published:
						<a class="u-url" href={ templ.SafeURL(post.URL) }>
							@postDate(post.Date, "dt-published")
						</a>
					</span>
					// one commit: not updated
					if len(post.Commits) > 1 {
						<span class="date last-updated">
							Last updated:
							<a href={ templ.URL(post.Commits[0].Link.String()) }>
								@postDate(post.Commits[0].Date, "dt-updated")
							</a>
						</span>
					}
				</p>
			</header>
			<div class="e-content">
				@post
			</div>
			<div class="tags">
				Tags:
				<ul class="p-categories tags">
					for _, tag := range post.Taxonomies.Tags {
						<li>
							@tagLink(tag, templ.Attributes{"class": "p-category"})
						</li>
					}
				</ul>
			</div>
		</article>
	}
}