From f76093690c0b3a1364269e0bfc9086ac9f60f184 Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Mon, 9 Apr 2018 20:30:55 -0700 Subject: Get the right comments URL when having multiple namespaces --- reader/rss/parser_test.go | 7 +++++-- reader/rss/rss.go | 43 +++++++++++++++++++++++++++++-------------- 2 files changed, 34 insertions(+), 16 deletions(-) (limited to 'reader/rss') diff --git a/reader/rss/parser_test.go b/reader/rss/parser_test.go index b75a8ff..f3ca697 100644 --- a/reader/rss/parser_test.go +++ b/reader/rss/parser_test.go @@ -583,13 +583,16 @@ func TestParseEntryWithRelativeURL(t *testing.T) { func TestParseEntryWithCommentsURL(t *testing.T) { data := ` - + https://example.org/ Item 1 https://example.org/item1 - https://example.org/comments + + https://example.org/comments + + 42 ` diff --git a/reader/rss/rss.go b/reader/rss/rss.go index bc901db..92335af 100644 --- a/reader/rss/rss.go +++ b/reader/rss/rss.go @@ -38,20 +38,25 @@ type rssLink struct { Rel string `xml:"rel,attr"` } +type rssCommentLink struct { + XMLName xml.Name + Data string `xml:",chardata"` +} + type rssItem struct { - GUID string `xml:"guid"` - Title string `xml:"title"` - Links []rssLink `xml:"link"` - OriginalLink string `xml:"http://rssnamespace.org/feedburner/ext/1.0 origLink"` - Comments string `xml:"comments"` - Description string `xml:"description"` - Content string `xml:"http://purl.org/rss/1.0/modules/content/ encoded"` - PubDate string `xml:"pubDate"` - Date string `xml:"http://purl.org/dc/elements/1.1/ date"` - Authors []rssAuthor `xml:"author"` - Creator string `xml:"http://purl.org/dc/elements/1.1/ creator"` - Enclosures []rssEnclosure `xml:"enclosure"` - OrigEnclosureLink string `xml:"http://rssnamespace.org/feedburner/ext/1.0 origEnclosureLink"` + GUID string `xml:"guid"` + Title string `xml:"title"` + Links []rssLink `xml:"link"` + OriginalLink string `xml:"http://rssnamespace.org/feedburner/ext/1.0 origLink"` + CommentLinks []rssCommentLink `xml:"comments"` + Description string `xml:"description"` + Content string `xml:"http://purl.org/rss/1.0/modules/content/ encoded"` + PubDate string `xml:"pubDate"` + Date string `xml:"http://purl.org/dc/elements/1.1/ date"` + Authors []rssAuthor `xml:"author"` + Creator string `xml:"http://purl.org/dc/elements/1.1/ creator"` + Enclosures []rssEnclosure `xml:"enclosure"` + OrigEnclosureLink string `xml:"http://rssnamespace.org/feedburner/ext/1.0 origEnclosureLink"` } type rssAuthor struct { @@ -217,10 +222,20 @@ func (r *rssItem) GetEnclosures() model.EnclosureList { return enclosures } +func (r *rssItem) CommentsURL() string { + for _, commentLink := range r.CommentLinks { + if commentLink.XMLName.Space == "" { + return strings.TrimSpace(commentLink.Data) + } + } + + return "" +} + func (r *rssItem) Transform() *model.Entry { entry := new(model.Entry) entry.URL = r.GetURL() - entry.CommentsURL = r.Comments + entry.CommentsURL = r.CommentsURL() entry.Date = r.GetDate() entry.Author = r.GetAuthor() entry.Hash = r.GetHash() -- cgit v1.2.3