diff options
author | Alan Pearce | 2024-06-18 16:46:22 +0200 |
---|---|---|
committer | Alan Pearce | 2024-06-18 16:46:22 +0200 |
commit | 1d247493e05cdc659e46cd3d8a01d5da1e893867 (patch) | |
tree | 221e9ee2f5e3f171dfd937f04fae7ad6a33588d8 /internal/builder/post.templ | |
parent | a238c7e0889cbe7dfaa1a700dea30686a4e2139a (diff) | |
download | website-1d247493e05cdc659e46cd3d8a01d5da1e893867.tar.lz website-1d247493e05cdc659e46cd3d8a01d5da1e893867.tar.zst website-1d247493e05cdc659e46cd3d8a01d5da1e893867.zip |
switch to templ for rendering HTML templates
Diffstat (limited to 'internal/builder/post.templ')
-rw-r--r-- | internal/builder/post.templ | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/internal/builder/post.templ b/internal/builder/post.templ new file mode 100644 index 0000000..740c5aa --- /dev/null +++ b/internal/builder/post.templ @@ -0,0 +1,50 @@ +package builder + +import ( + "time" + "website/internal/config" +) + +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 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> + } +} |