about summary refs log tree commit diff stats
path: root/internal/builder/homepage.templ
blob: 9897b5d645146944bc5dc95913912620f40aa25b (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
52
53
54
package builder

import (
	"website/internal/config"
	"path"
)

func getContent(filename string) templ.Component {
	return templ.ComponentFunc(func(ctx context.Context, w io.Writer) error {
		_, index, err := getPost(path.Join("content", filename))
		if err != nil {
			return err
		}
		_, err = io.WriteString(w, string(index))

		return err
	})
}

templ homepage(config config.Config, posts []Post) {
	@page(config, PageSettings{
		Title: config.Title,
		TitleAttrs: templ.Attributes{
			"class": "p-name u-url",
		},
		Path: "/",
		BodyAttrs: templ.Attributes{
			"class": "h-card",
		},
	}) {
		<div id="content">
			@getContent("_index.md")
		</div>
		<section>
			<h2>Latest Posts</h2>
			@list(posts[0:3])
		</section>
		<section>
			<h2>Elsewhere on the Internet</h2>
			<ul class="elsewhere">
				<li>
					<a class="u-email" rel="me" href={ templ.SafeURL("mailto:" + config.Email) }>
						{ config.Email }
					</a>
				</li>
				for _, link := range config.Menus["me"] {
					<li>
						<a class="u-url" rel="me" href={ templ.SafeURL(link.URL) }>{ link.Name }</a>
					</li>
				}
			</ul>
		</section>
	}
}