summaryrefslogtreecommitdiff
path: root/reader
diff options
context:
space:
mode:
authorGravatar Dave Marquard <dave@marquard.org> 2021-07-21 08:14:25 -0700
committerGravatar fguillot <f@miniflux.net> 2021-07-21 21:28:37 -0700
commitfc766de02d1937412c8291e9afe255a13136ddf7 (patch)
tree82101118b9f6d9bbc0de898bd9c8869a86d0c00f /reader
parent79810413bdf22be76f95a1e0380d36935cc8d0d7 (diff)
downloadv2-fc766de02d1937412c8291e9afe255a13136ddf7.tar.gz
v2-fc766de02d1937412c8291e9afe255a13136ddf7.tar.zst
v2-fc766de02d1937412c8291e9afe255a13136ddf7.zip
use authors entry for json 1.1 feeds
Diffstat (limited to 'reader')
-rw-r--r--reader/json/json.go20
-rw-r--r--reader/json/parser_test.go43
2 files changed, 57 insertions, 6 deletions
diff --git a/reader/json/json.go b/reader/json/json.go
index 65b44e58..31ba961c 100644
--- a/reader/json/json.go
+++ b/reader/json/json.go
@@ -16,12 +16,13 @@ import (
)
type jsonFeed struct {
- Version string `json:"version"`
- Title string `json:"title"`
- SiteURL string `json:"home_page_url"`
- FeedURL string `json:"feed_url"`
- Author jsonAuthor `json:"author"`
- Items []jsonItem `json:"items"`
+ Version string `json:"version"`
+ Title string `json:"title"`
+ SiteURL string `json:"home_page_url"`
+ FeedURL string `json:"feed_url"`
+ Authors []jsonAuthor `json:"authors"`
+ Author jsonAuthor `json:"author"`
+ Items []jsonItem `json:"items"`
}
type jsonAuthor struct {
@@ -38,6 +39,7 @@ type jsonItem struct {
HTML string `json:"content_html"`
DatePublished string `json:"date_published"`
DateModified string `json:"date_modified"`
+ Authors []jsonAuthor `json:"authors"`
Author jsonAuthor `json:"author"`
Attachments []jsonAttachment `json:"attachments"`
}
@@ -51,6 +53,9 @@ type jsonAttachment struct {
}
func (j *jsonFeed) GetAuthor() string {
+ if len(j.Authors) > 0 {
+ return (getAuthor(j.Authors[0]))
+ }
return getAuthor(j.Author)
}
@@ -108,6 +113,9 @@ func (j *jsonItem) GetDate() time.Time {
}
func (j *jsonItem) GetAuthor() string {
+ if len(j.Authors) > 0 {
+ return getAuthor(j.Authors[0])
+ }
return getAuthor(j.Author)
}
diff --git a/reader/json/parser_test.go b/reader/json/parser_test.go
index 81eaf497..0bd6e6c7 100644
--- a/reader/json/parser_test.go
+++ b/reader/json/parser_test.go
@@ -272,6 +272,49 @@ func TestParseAuthor(t *testing.T) {
}
}
+func TestParseAuthors(t *testing.T) {
+ data := `{
+ "version": "https://jsonfeed.org/version/1.1",
+ "user_comment": "This is a microblog feed. You can add this to your feed reader using the following URL: https://example.org/feed.json",
+ "title": "Brent Simmons’s Microblog",
+ "home_page_url": "https://example.org/",
+ "feed_url": "https://example.org/feed.json",
+ "author": {
+ "name": "This field is deprecated, use authors",
+ "url": "http://example.org/",
+ "avatar": "https://example.org/avatar.png"
+ },
+ "authors": [
+ {
+ "name": "Brent Simmons",
+ "url": "http://example.org/",
+ "avatar": "https://example.org/avatar.png"
+ }
+ ],
+ "items": [
+ {
+ "id": "2347259",
+ "url": "https://example.org/2347259",
+ "content_text": "Cats are neat. \n\nhttps://example.org/cats",
+ "date_published": "2016-02-09T14:22:00-07:00"
+ }
+ ]
+ }`
+
+ feed, err := Parse("https://example.org/feed.json", bytes.NewBufferString(data))
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ if len(feed.Entries) != 1 {
+ t.Errorf("Incorrect number of entries, got: %d", len(feed.Entries))
+ }
+
+ if feed.Entries[0].Author != "Brent Simmons" {
+ t.Errorf("Incorrect entry author, got: %s", feed.Entries[0].Author)
+ }
+}
+
func TestParseFeedWithoutTitle(t *testing.T) {
data := `{
"version": "https://jsonfeed.org/version/1",