render webmentions in post

This commit is contained in:
Niko Abeler 2022-09-01 22:01:36 +02:00
parent 8d1dacc1f5
commit 4aaa14e30c
2 changed files with 62 additions and 0 deletions

View File

@ -13,4 +13,24 @@
<div class="e-content">
{{.Content}}
</div>
<hr>
{{if .Post.ApprovedWebmentions}}
<h3>
Webmentions
</h3>
<ul>
{{range .Post.ApprovedWebmentions}}
<li>
<a href="{{.Source}}">
{{if .Title}}
{{.Title}}
{{else}}
{{.Source}}
{{end}}
</a>
</li>
{{end}}
</ul>
{{end}}
</div>

View File

@ -6,6 +6,7 @@ import (
"path"
"strings"
"testing"
"time"
)
func TestCanRenderPost(t *testing.T) {
@ -157,3 +158,44 @@ func TestRenderPostIncludesRelToWebMention(t *testing.T) {
t.Error("webmention href not rendered. Got: " + result)
}
}
func TestRenderPostAddsLinksToApprovedWebmention(t *testing.T) {
user := getTestUser()
post, _ := user.CreateNewPost("testpost")
webmention := owl.Webmention{
Source: "http://example.com/source3",
Title: "Test Title",
ApprovalStatus: "approved",
RetrievedAt: time.Now().Add(time.Hour * -2),
}
post.PersistWebmention(webmention)
webmention = owl.Webmention{
Source: "http://example.com/source4",
ApprovalStatus: "rejected",
RetrievedAt: time.Now().Add(time.Hour * -3),
}
post.PersistWebmention(webmention)
result, _ := owl.RenderPost(&post)
if !strings.Contains(result, "http://example.com/source3") {
t.Error("webmention not rendered. Got: " + result)
}
if !strings.Contains(result, "Test Title") {
t.Error("webmention title not rendered. Got: " + result)
}
if strings.Contains(result, "http://example.com/source4") {
t.Error("unapproved webmention rendered. Got: " + result)
}
}
func TestRenderPostNotMentioningWebmentionsIfNoAvail(t *testing.T) {
user := getTestUser()
post, _ := user.CreateNewPost("testpost")
result, _ := owl.RenderPost(&post)
if strings.Contains(result, "Webmention") {
t.Error("Webmention mentioned. Got: " + result)
}
}