Skip to content

Commit

Permalink
Force published field (#147)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
guilhem committed Apr 8, 2021
1 parent 1850ec1 commit 68eef24
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
Expand Up @@ -2,7 +2,9 @@
"items": [
{
"updated": "Thu, 01 Jan 2004 19:48:21 GMT",
"updatedParsed": "2004-01-01T19:48:21Z"
"updatedParsed": "2004-01-01T19:48:21Z",
"published": "Thu, 01 Jan 2004 19:48:21 GMT",
"publishedParsed": "2004-01-01T19:48:21Z"
}
],
"feedType": "atom",
Expand Down
16 changes: 12 additions & 4 deletions translator.go
Expand Up @@ -643,12 +643,20 @@ func (t *DefaultAtomTranslator) translateItemUpdatedParsed(entry *atom.Entry) (u
return entry.UpdatedParsed
}

func (t *DefaultAtomTranslator) translateItemPublished(entry *atom.Entry) (updated string) {
return entry.Published
func (t *DefaultAtomTranslator) translateItemPublished(entry *atom.Entry) (published string) {
published = entry.Published
if published == "" {
published = entry.Updated
}
return
}

func (t *DefaultAtomTranslator) translateItemPublishedParsed(entry *atom.Entry) (updated *time.Time) {
return entry.PublishedParsed
func (t *DefaultAtomTranslator) translateItemPublishedParsed(entry *atom.Entry) (published *time.Time) {
published = entry.PublishedParsed
if published == nil {
published = entry.UpdatedParsed
}
return
}

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

0 comments on commit 68eef24

Please sign in to comment.