From 1d247493e05cdc659e46cd3d8a01d5da1e893867 Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Tue, 18 Jun 2024 16:46:22 +0200 Subject: switch to templ for rendering HTML templates --- internal/builder/homepage.templ | 54 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 internal/builder/homepage.templ (limited to 'internal/builder/homepage.templ') 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", + }, + }) { +
+ @getContent("_index.md") +
+
+

Latest Posts

+ @list(posts[0:3]) +
+
+

Elsewhere on the Internet

+ +
+ } +} -- cgit 1.4.1