feat(atom): use id for entry link if it is an http URL

This commit is contained in:
Kelly Norton
2026-06-03 06:34:48 -04:00
committed by fguillot
parent 510d225b06
commit 51f2e0d819
2 changed files with 38 additions and 0 deletions
+10
View File
@@ -81,6 +81,16 @@ func (a *atom10Adapter) populateEntries(siteURL string) model.Entries {
}
}
// If the entry has no links, attempt to use its ID as a URL
// and if that fails, use the site URL.
if entry.URL == "" {
if urllib.IsAbsoluteURL(atomEntry.ID) {
entry.URL = atomEntry.ID
} else {
entry.URL = siteURL
}
}
// Populate the entry content.
entry.Content = atomEntry.Content.body()
if entry.Content == "" {
+28
View File
@@ -1837,3 +1837,31 @@ func TestParseFeedWithIconURL(t *testing.T) {
t.Errorf("Incorrect icon URL, got: %s", feed.IconURL)
}
}
func TestParseEntryWithIDAsURL(t *testing.T) {
data := `<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>Example Feed</title>
<link href="http://example.org/"/>
<link href="http://example.org/atom" rel="self"/>
<entry>
<id>http://www.example.org/entries/1</id>
</entry>
<entry>
<id>mailto:john.doe@example.org</id>
</entry>
</feed>`
feed, err := Parse("https://example.org/", bytes.NewReader([]byte(data)), "10")
if err != nil {
t.Fatal(err)
}
if feed.Entries[0].URL != "http://www.example.org/entries/1" {
t.Errorf("Incorrect entry URL, got: %s", feed.Entries[0].URL)
}
if feed.Entries[1].URL != "http://example.org/" {
t.Errorf("Incorrect entry URL, got: %s", feed.Entries[1].URL)
}
}