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 Jul 10, 2024
1 parent 70c9e42 commit 932fea1
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 @@ -74,6 +74,8 @@ func (t *DefaultRSSTranslator) translateFeedItem(rssItem *rss.Item) (item *Item)
item.Links = t.translateItemLinks(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 @@ -332,18 +334,20 @@ func (t *DefaultRSSTranslator) translateItemLinks(rssItem *rss.Item) (links []st
}

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 932fea1

Please sign in to comment.