Send webmention to reply url

This commit is contained in:
Niko Abeler 2022-10-10 21:06:33 +02:00
parent 9056b22536
commit 1c53244439
2 changed files with 29 additions and 0 deletions

View File

@ -385,6 +385,10 @@ func (post *Post) ScanForLinks() error {
// rely on goldmark for this (yet)
postHtml := post.RenderedContent()
links, _ := post.user.repo.Parser.ParseLinksFromString(postHtml.String())
// add reply url if set
if post.Meta().Reply.Url != "" {
links = append(links, post.Meta().Reply.Url)
}
for _, link := range links {
post.PersistOutgoingWebmention(&WebmentionOut{
Target: link,

View File

@ -344,6 +344,31 @@ func TestScanningForLinksDoesNotAddDuplicates(t *testing.T) {
}
}
func TestScanningForLinksDoesAddReplyUrl(t *testing.T) {
repo := getTestRepo(owl.RepoConfig{})
user, _ := repo.CreateUser("testuser")
post, _ := user.CreateNewPost("testpost")
content := "---\n"
content += "title: test\n"
content += "date: Wed, 17 Aug 2022 10:50:02 +0000\n"
content += "reply:\n"
content += " url: https://example.com/reply\n"
content += "---\n"
content += "\n"
content += "Hi\n"
os.WriteFile(post.ContentFile(), []byte(content), 0644)
post.ScanForLinks()
webmentions := post.OutgoingWebmentions()
if len(webmentions) != 1 {
t.Errorf("Expected 1 webmention, got %d", len(webmentions))
}
if webmentions[0].Target != "https://example.com/reply" {
t.Errorf("Expected target: %s, got %s", "https://example.com/reply", webmentions[0].Target)
}
}
func TestCanSendWebmention(t *testing.T) {
repo := getTestRepo(owl.RepoConfig{})
repo.HttpClient = &MockHttpClient{}