Skip to content

Commit

Permalink
mmcdole#151: Support for atom update date
Browse files Browse the repository at this point in the history
  • Loading branch information
Necoro committed Feb 25, 2021
1 parent 68f7504 commit dc1f362
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"items": [
{
"updated": "Thu, 01 Jan 2004 19:48:21 GMT",
"updatedParsed": "2004-01-01T19:48:21Z",
"extensions": {
"atom": {
"updated": [
{
"name": "updated",
"value": "",
"parsed": {
"updated": "Thu, 01 Jan 2004 19:48:21 GMT",
"updatedParsed": "2004-01-01T19:48:21Z"
}
}
]
}
}
}
],
"feedType": "rss",
"feedVersion": "2.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!--
Description: item updated (atom)
-->
<rss version="2.0" xmlns:a10="http://www.w3.org/2005/Atom">
<channel>
<item>
<a10:updated>Thu, 01 Jan 2004 19:48:21 GMT</a10:updated>
</item>
</channel>
</rss>
12 changes: 8 additions & 4 deletions translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ func (t *DefaultRSSTranslator) translateFeedItem(rssItem *rss.Item) (item *Item)
item.Link = t.translateItemLink(rssItem)
item.Published = t.translateItemPublished(rssItem)
item.PublishedParsed = t.translateItemPublishedParsed(rssItem)
item.Updated = t.translateItemUpdated(rssItem)
item.UpdatedParsed = t.translateItemUpdatedParsed(rssItem)
item.Author = t.translateItemAuthor(rssItem)
item.Authors = t.translateItemAuthors(rssItem)
item.GUID = t.translateItemGUID(rssItem)
Expand Down Expand Up @@ -289,18 +291,20 @@ func (t *DefaultRSSTranslator) translateItemLink(rssItem *rss.Item) (link string
}

func (t *DefaultRSSTranslator) translateItemUpdated(rssItem *rss.Item) (updated string) {
if rssItem.DublinCoreExt != nil && rssItem.DublinCoreExt.Date != nil {
if updatedVal, ok := t.hasAtomExtensionsForKey(rssItem, "updated"); ok {
updated = t.atomTranslator.translateItemUpdated(updatedVal)
} else if rssItem.DublinCoreExt != nil && rssItem.DublinCoreExt.Date != nil {
updated = t.firstEntry(rssItem.DublinCoreExt.Date)
}
return updated
}

func (t *DefaultRSSTranslator) translateItemUpdatedParsed(rssItem *rss.Item) (updated *time.Time) {
if rssItem.DublinCoreExt != nil && rssItem.DublinCoreExt.Date != nil {
updatedText := t.firstEntry(rssItem.DublinCoreExt.Date)
if updatedText := t.translateItemUpdated(rssItem); updatedText != "" {
updatedDate, err := shared.ParseDate(updatedText)
if err == nil {
updated = &updatedDate
utcDate := updatedDate.UTC()
updated = &utcDate
}
}
return
Expand Down

0 comments on commit dc1f362

Please sign in to comment.