diff options
Diffstat (limited to 'templates/post.templ')
-rw-r--r-- | templates/post.templ | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/templates/post.templ b/templates/post.templ new file mode 100644 index 0000000..1a5495c --- /dev/null +++ b/templates/post.templ @@ -0,0 +1,59 @@ +package templates + +import ( + "context" + "io" + "time" + + "go.alanpearce.eu/website/internal/config" + "go.alanpearce.eu/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", + }, + BodyAttrs: templ.Attributes{ + "class": "h-entry", + }, + Path: post.URL, + }) { + <article> + <h1 class="p-name">{ post.Title }</h1> + <p> + <a class="u-url" href={ templ.SafeURL(post.URL) }> + @postDate(post.Date) + </a> + </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> + } +} |