mirror of
https://github.com/nkanaev/yarr.git
synced 2025-05-24 00:33:14 +00:00
handle isPermalink in rss feeds
This commit is contained in:
parent
7d99edab8d
commit
bc18557820
@ -14,6 +14,7 @@
|
|||||||
- (fix) keyboard shortcuts in Firefox (thanks to @kaloyan13)
|
- (fix) keyboard shortcuts in Firefox (thanks to @kaloyan13)
|
||||||
- (fix) keyboard shortcuts in non-English layouts (thanks to @kaloyan13)
|
- (fix) keyboard shortcuts in non-English layouts (thanks to @kaloyan13)
|
||||||
- (fix) sorting articles with timezone information (thanks to @x2cf)
|
- (fix) sorting articles with timezone information (thanks to @x2cf)
|
||||||
|
- (fix) handling links set in guid only for certain feeds (thanks to @adaszko for the report)
|
||||||
|
|
||||||
# v2.3 (2022-05-03)
|
# v2.3 (2022-05-03)
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ type rssFeed struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type rssItem struct {
|
type rssItem struct {
|
||||||
GUID string `xml:"guid"`
|
GUID rssGuid `xml:"guid"`
|
||||||
Title string `xml:"title"`
|
Title string `xml:"title"`
|
||||||
Link string `xml:"rss link"`
|
Link string `xml:"rss link"`
|
||||||
Description string `xml:"rss description"`
|
Description string `xml:"rss description"`
|
||||||
@ -36,6 +36,11 @@ type rssItem struct {
|
|||||||
media
|
media
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type rssGuid struct {
|
||||||
|
GUID string `xml:",chardata"`
|
||||||
|
IsPermaLink string `xml:"isPermaLink,attr"`
|
||||||
|
}
|
||||||
|
|
||||||
type rssLink struct {
|
type rssLink struct {
|
||||||
XMLName xml.Name
|
XMLName xml.Name
|
||||||
Data string `xml:",chardata"`
|
Data string `xml:",chardata"`
|
||||||
@ -81,10 +86,15 @@ func ParseRSS(r io.Reader) (*Feed, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
permalink := ""
|
||||||
|
if srcitem.GUID.IsPermaLink == "true" {
|
||||||
|
permalink = srcitem.GUID.GUID
|
||||||
|
}
|
||||||
|
|
||||||
dstfeed.Items = append(dstfeed.Items, Item{
|
dstfeed.Items = append(dstfeed.Items, Item{
|
||||||
GUID: firstNonEmpty(srcitem.GUID, srcitem.Link),
|
GUID: firstNonEmpty(srcitem.GUID.GUID, srcitem.Link),
|
||||||
Date: dateParse(firstNonEmpty(srcitem.DublinCoreDate, srcitem.PubDate)),
|
Date: dateParse(firstNonEmpty(srcitem.DublinCoreDate, srcitem.PubDate)),
|
||||||
URL: firstNonEmpty(srcitem.OrigLink, srcitem.Link),
|
URL: firstNonEmpty(srcitem.OrigLink, srcitem.Link, permalink),
|
||||||
Title: srcitem.Title,
|
Title: srcitem.Title,
|
||||||
Content: firstNonEmpty(srcitem.ContentEncoded, srcitem.Description),
|
Content: firstNonEmpty(srcitem.ContentEncoded, srcitem.Description),
|
||||||
AudioURL: podcastURL,
|
AudioURL: podcastURL,
|
||||||
|
@ -203,3 +203,28 @@ func TestRSSTitleHTMLTags(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRSSIsPermalink(t *testing.T) {
|
||||||
|
feed, _ := Parse(strings.NewReader(`
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
|
||||||
|
<channel>
|
||||||
|
<item>
|
||||||
|
<guid isPermaLink="true">http://example.com/posts/1</guid>
|
||||||
|
</item>
|
||||||
|
</channel>
|
||||||
|
</rss>
|
||||||
|
`))
|
||||||
|
have := feed.Items
|
||||||
|
want := []Item{
|
||||||
|
{
|
||||||
|
GUID: "http://example.com/posts/1",
|
||||||
|
URL: "http://example.com/posts/1",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for i := 0; i < len(want); i++ {
|
||||||
|
if want[i] != have[i] {
|
||||||
|
t.Errorf("Failed to handle isPermalink\nwant: %#v\nhave: %#v\n", want[i], have[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user