about summary refs log tree commit diff stats
path: root/templates/post.templ
blob: 5b09d4be01ac5ac870b76508debc9e36e5913964 (plain)
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
package templates

import (
	"time"
	"website/internal/config"
	"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) {
	<time class="dt-published" datetime={ d.UTC().Format(time.RFC3339) }>
		{ d.Format("2006-01-02") }
	</time>
}

templ PostPage(config config.Config, post content.Post) {
	@Page(config, PageSettings{
		Title: post.Title,
		TitleAttrs: templ.Attributes{
			"class": "p-author h-card",
			"rel":   "author",
		},
		Path: post.URL,
	}) {
		<article class="h-entry">
			<h1 class="p-name">{ post.Title }</h1>
			<p>
				@postDate(post.Date)
			</p>
			<div class="e-content">
				@Unsafe(post.Content)
			</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>
	}
}