Skip to content

Commit 68eef24

Browse files
authored
Force published field (#147)
* Force published field When an atom item only have updated field, use it to fill published. - Less function is using published field, it has to always been populated. - Simplify code when using both RSS and Atom feeds. This fix #146 * Rename updated to published following @Necoro comment
1 parent 1850ec1 commit 68eef24

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

testdata/translator/atom/feed_item_updated_-_atom03_feed_entry_modified.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
"items": [
33
{
44
"updated": "Thu, 01 Jan 2004 19:48:21 GMT",
5-
"updatedParsed": "2004-01-01T19:48:21Z"
5+
"updatedParsed": "2004-01-01T19:48:21Z",
6+
"published": "Thu, 01 Jan 2004 19:48:21 GMT",
7+
"publishedParsed": "2004-01-01T19:48:21Z"
68
}
79
],
810
"feedType": "atom",

translator.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -643,12 +643,20 @@ func (t *DefaultAtomTranslator) translateItemUpdatedParsed(entry *atom.Entry) (u
643643
return entry.UpdatedParsed
644644
}
645645

646-
func (t *DefaultAtomTranslator) translateItemPublished(entry *atom.Entry) (updated string) {
647-
return entry.Published
646+
func (t *DefaultAtomTranslator) translateItemPublished(entry *atom.Entry) (published string) {
647+
published = entry.Published
648+
if published == "" {
649+
published = entry.Updated
650+
}
651+
return
648652
}
649653

650-
func (t *DefaultAtomTranslator) translateItemPublishedParsed(entry *atom.Entry) (updated *time.Time) {
651-
return entry.PublishedParsed
654+
func (t *DefaultAtomTranslator) translateItemPublishedParsed(entry *atom.Entry) (published *time.Time) {
655+
published = entry.PublishedParsed
656+
if published == nil {
657+
published = entry.UpdatedParsed
658+
}
659+
return
652660
}
653661

654662
func (t *DefaultAtomTranslator) translateItemAuthor(entry *atom.Entry) (author *Person) {

0 commit comments

Comments
 (0)