Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Ability to parse custom fields in rss that are not part of the spec #177

Merged
merged 1 commit into from
Apr 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions rss/feed.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ type Item struct {
DublinCoreExt *ext.DublinCoreExtension `json:"dcExt,omitempty"`
ITunesExt *ext.ITunesItemExtension `json:"itunesExt,omitempty"`
Extensions ext.Extensions `json:"extensions,omitempty"`
Custom map[string]string `json:"custom,omitempty"`
}

// Image is an image that represents the feed
Expand Down
10 changes: 8 additions & 2 deletions rss/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,14 @@ func (rp *Parser) parseItem(p *xpp.XMLPullParser) (item *Item, err error) {
}
categories = append(categories, result)
} else {
// Skip any elements not part of the item spec
p.Skip()
result, err := shared.ParseText(p)
if err != nil {
continue
}
if item.Custom == nil {
item.Custom = make(map[string]string, 0)
}
item.Custom[name] = result
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions testdata/parser/rss/rss_channel_item_custom.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"items": [
{
"custom": {
"apcategory": "s",
"test": "test"
}
}
],
"version": "2.0"
}
11 changes: 11 additions & 0 deletions testdata/parser/rss/rss_channel_item_custom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!--
Description: rss item categories
-->
<rss version="2.0">
<channel>
<item>
<apcategory>s</apcategory>
<test>test</test>
</item>
</channel>
</rss>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"items": [
{
"custom": {
"apcategory": "s",
"test": "test"
}
}
],
"feedType": "rss",
"feedVersion": "2.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<rss version="2.0">
<channel>
<item>
<test>test</test>
<apcategory>s</apcategory>
</item>
</channel>
</rss>
1 change: 1 addition & 0 deletions translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func (t *DefaultRSSTranslator) translateFeedItem(rssItem *rss.Item) (item *Item)
item.DublinCoreExt = rssItem.DublinCoreExt
item.ITunesExt = rssItem.ITunesExt
item.Extensions = rssItem.Extensions
item.Custom = rssItem.Custom
return
}

Expand Down