about summary refs log tree commit diff stats
path: root/internal/builder/homepage.templ
diff options
context:
space:
mode:
authorAlan Pearce2024-06-18 16:46:22 +0200
committerAlan Pearce2024-06-18 16:46:22 +0200
commit1d247493e05cdc659e46cd3d8a01d5da1e893867 (patch)
tree221e9ee2f5e3f171dfd937f04fae7ad6a33588d8 /internal/builder/homepage.templ
parenta238c7e0889cbe7dfaa1a700dea30686a4e2139a (diff)
downloadwebsite-1d247493e05cdc659e46cd3d8a01d5da1e893867.tar.lz
website-1d247493e05cdc659e46cd3d8a01d5da1e893867.tar.zst
website-1d247493e05cdc659e46cd3d8a01d5da1e893867.zip
switch to templ for rendering HTML templates
Diffstat (limited to 'internal/builder/homepage.templ')
-rw-r--r--internal/builder/homepage.templ54
1 files changed, 54 insertions, 0 deletions
diff --git a/internal/builder/homepage.templ b/internal/builder/homepage.templ
new file mode 100644
index 0000000..9897b5d
--- /dev/null
+++ b/internal/builder/homepage.templ
@@ -0,0 +1,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>
+	}
+}