added publishing date to post and post list with microformat tags

This commit is contained in:
Niko Abeler 2022-08-22 21:35:50 +02:00
parent 769c4133d5
commit 179559250a
5 changed files with 33 additions and 15 deletions

View File

@ -102,7 +102,7 @@ func postHandler(repo *owl.Repository) func(http.ResponseWriter, *http.Request,
return
}
html, err := owl.RenderPost(post)
html, err := owl.RenderPost(&post)
if err != nil {
println("Error rendering post: ", err.Error())
w.WriteHeader(http.StatusInternalServerError)

View File

@ -1,10 +1,16 @@
<div class="h-feed">
{{range .}}
<div class="h-entry">
<h3 style="margin-bottom:0;"><a class="u-url" href="{{.UrlPath}}">{{.Title}}</a></h3>
<div>Published: {{.Meta.Date}}</div>
<hgroup>
<h3><a class="u-url" href="{{.UrlPath}}">{{.Title}}</a></h3>
<small>
Published:
<time class="dt-published" datetime="{{.Meta.Date}}">
{{.Meta.Date}}
</time>
</small>
</hgroup>
</div>
<hr>
<br>
{{end}}
</div>

View File

@ -1,6 +1,16 @@
<div class="h-entry">
<h1 class="p-name">{{.Title}}</h1>
<hgroup>
<h1 class="p-name">{{.Title}}</h1>
<small>
Published:
<time class="dt-published" datetime="{{.Post.Meta.Date}}">
{{.Post.Meta.Date}}
</time>
</small>
</hgroup>
<hr>
<br>
<div class="e-content">
{{.Post}}
{{.Content}}
</div>
</div>

View File

@ -12,8 +12,9 @@ type PageContent struct {
}
type PostRenderData struct {
Title string
Post template.HTML
Title string
Post *Post
Content template.HTML
}
func renderEmbedTemplate(templateFile string, data interface{}) (string, error) {
@ -67,11 +68,12 @@ func renderIntoBaseTemplate(user User, data PageContent) (string, error) {
return html.String(), nil
}
func RenderPost(post Post) (string, error) {
func RenderPost(post *Post) (string, error) {
buf := post.RenderedContent()
postHtml, err := renderEmbedTemplate("embed/post.html", PostRenderData{
Title: post.Title(),
Post: template.HTML(buf.String()),
Title: post.Title(),
Post: post,
Content: template.HTML(buf.String()),
})
if err != nil {
return "", err

View File

@ -11,7 +11,7 @@ import (
func TestCanRenderPost(t *testing.T) {
user := getTestUser()
post, _ := user.CreateNewPost("testpost")
result, err := owl.RenderPost(post)
result, err := owl.RenderPost(&post)
if err != nil {
t.Error("Error rendering post: " + err.Error())
@ -27,7 +27,7 @@ func TestCanRenderPost(t *testing.T) {
func TestRenderPostHEntry(t *testing.T) {
user := getTestUser()
post, _ := user.CreateNewPost("testpost")
result, _ := owl.RenderPost(post)
result, _ := owl.RenderPost(&post)
if !strings.Contains(result, "class=\"h-entry\"") {
t.Error("h-entry container not rendered. Got: " + result)
}
@ -43,7 +43,7 @@ func TestRenderPostHEntry(t *testing.T) {
func TestRendererUsesBaseTemplate(t *testing.T) {
user := getTestUser()
post, _ := user.CreateNewPost("testpost")
result, err := owl.RenderPost(post)
result, err := owl.RenderPost(&post)
if err != nil {
t.Error("Error rendering post: " + err.Error())
@ -132,7 +132,7 @@ func TestRendersHeaderTitle(t *testing.T) {
})
post, _ := user.CreateNewPost("testpost")
result, _ := owl.RenderPost(post)
result, _ := owl.RenderPost(&post)
if !strings.Contains(result, "Test Title") {
t.Error("Header title not rendered. Got: " + result)
}