h-feed and h-entry for microformats. #6

This commit is contained in:
Niko Abeler 2022-08-18 21:32:50 +02:00
parent defe031bc3
commit e176729358
3 changed files with 53 additions and 5 deletions

View File

@ -1,3 +1,7 @@
<div class="h-feed">
{{range .}} {{range .}}
<h2><a href="{{.UrlPath}}">{{.Title}}</a></h2> <div class="h-entry">
{{end}} <h2><a class="u-url" href="{{.UrlPath}}">{{.Title}}</a></h2>
</div>
{{end}}
</div>

View File

@ -1,2 +1,6 @@
<h1>{{.Title}}</h1> <div class="h-entry">
{{.Post}} <h1 class="p-name">{{.Title}}</h1>
<div class="e-content">
{{.Post}}
</div>
</div>

View File

@ -18,12 +18,28 @@ func TestCanRenderPost(t *testing.T) {
return return
} }
if !strings.Contains(result, "<h1>testpost</h1>") { if !strings.Contains(result, "<h1 class=\"p-name\">testpost</h1>") {
t.Error("Post title not rendered as h1. Got: " + result) t.Error("Post title not rendered as h1. Got: " + result)
} }
} }
func TestRenderPostHEntry(t *testing.T) {
user := getTestUser()
post, _ := user.CreateNewPost("testpost")
result, _ := owl.RenderPost(post)
if !strings.Contains(result, "class=\"h-entry\"") {
t.Error("h-entry container not rendered. Got: " + result)
}
if !strings.Contains(result, "class=\"p-name\"") {
t.Error("p-name not rendered. Got: " + result)
}
if !strings.Contains(result, "class=\"e-content\"") {
t.Error("e-content not rendered. Got: " + result)
}
}
func TestRendererUsesBaseTemplate(t *testing.T) { func TestRendererUsesBaseTemplate(t *testing.T) {
user := getTestUser() user := getTestUser()
post, _ := user.CreateNewPost("testpost") post, _ := user.CreateNewPost("testpost")
@ -52,6 +68,30 @@ func TestCanRenderIndexPage(t *testing.T) {
} }
} }
func TestIndexPageContainsHFeedContainer(t *testing.T) {
user := getTestUser()
user.CreateNewPost("testpost1")
result, _ := owl.RenderIndexPage(user)
if !strings.Contains(result, "<div class=\"h-feed\">") {
t.Error("h-feed container not rendered. Got: " + result)
}
}
func TestIndexPageContainsHEntryAndUUrl(t *testing.T) {
user := getTestUser()
user.CreateNewPost("testpost1")
result, _ := owl.RenderIndexPage(user)
if !strings.Contains(result, "class=\"h-entry\"") {
t.Error("h-entry container not rendered. Got: " + result)
}
if !strings.Contains(result, "class=\"u-url\"") {
t.Error("u-url not rendered. Got: " + result)
}
}
func TestRenderIndexPageWithBrokenBaseTemplate(t *testing.T) { func TestRenderIndexPageWithBrokenBaseTemplate(t *testing.T) {
user := getTestUser() user := getTestUser()
user.CreateNewPost("testpost1") user.CreateNewPost("testpost1")