diff --git a/README.md b/README.md index e08d110..7d7137b 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ applications. [atom]: https://tools.ietf.org/html/rfc4287 [rss]: http://www.rssboard.org/rss-specification -[jsonfeed]: https://jsonfeed.org/version/1 +[jsonfeed]: https://jsonfeed.org/version/1.1 ### Usage @@ -151,13 +151,18 @@ Outputs: { - "version": "https://jsonfeed.org/version/1", + "version": "https://jsonfeed.org/version/1.1", "title": "jmoiron.net blog", "home_page_url": "http://jmoiron.net/blog", "description": "discussion about tech, footie, photos", "author": { "name": "Jason Moiron" }, + "authors": [ + { + "name": "Jason Moiron" + } + ], "items": [ { "id": "", @@ -167,7 +172,12 @@ Outputs: "date_published": "2013-01-16T03:22:24.530817846-05:00", "author": { "name": "Jason Moiron" - } + }, + "authors": [ + { + "name": "Jason Moiron" + } + ] }, { "id": "", diff --git a/feed_test.go b/feed_test.go index 2a37f2a..837cfa6 100644 --- a/feed_test.go +++ b/feed_test.go @@ -121,13 +121,18 @@ var rssOutput = `` var jsonOutput = `{ - "version": "https://jsonfeed.org/version/1", + "version": "https://jsonfeed.org/version/1.1", "title": "jmoiron.net blog", "home_page_url": "http://jmoiron.net/blog", "description": "discussion about tech, footie, photos", "author": { "name": "Jason Moiron" }, + "authors": [ + { + "name": "Jason Moiron" + } + ], "items": [ { "id": "", @@ -138,7 +143,12 @@ var jsonOutput = `{ "date_published": "2013-01-16T21:52:35-05:00", "author": { "name": "Jason Moiron" - } + }, + "authors": [ + { + "name": "Jason Moiron" + } + ] }, { "id": "", @@ -369,13 +379,18 @@ var rssOutputSorted = `` var jsonOutputSorted = `{ - "version": "https://jsonfeed.org/version/1", + "version": "https://jsonfeed.org/version/1.1", "title": "jmoiron.net blog", "home_page_url": "http://jmoiron.net/blog", "description": "discussion about tech, footie, photos", "author": { "name": "Jason Moiron" }, + "authors": [ + { + "name": "Jason Moiron" + } + ], "items": [ { "id": "", @@ -572,7 +587,7 @@ func TestJSONHub(t *testing.T) { Version: "https://jsonfeed.org/version/1", Title: "feed title", Hubs: []*JSONHub{ - &JSONHub{ + { Type: "WebSub", Url: "https://websub-hub.example", }, diff --git a/json.go b/json.go index 0302c22..ae5deb7 100644 --- a/json.go +++ b/json.go @@ -6,7 +6,7 @@ import ( "time" ) -const jsonFeedVersion = "https://jsonfeed.org/version/1" +const jsonFeedVersion = "https://jsonfeed.org/version/1.1" // JSONAuthor represents the author of the feed or of an individual item // in the feed @@ -77,7 +77,8 @@ type JSONItem struct { BannerImage string `json:"banner_,omitempty"` PublishedDate *time.Time `json:"date_published,omitempty"` ModifiedDate *time.Time `json:"date_modified,omitempty"` - Author *JSONAuthor `json:"author,omitempty"` + Author *JSONAuthor `json:"author,omitempty"` // deprecated in JSON Feed v1.1, keeping for backwards compatibility + Authors []*JSONAuthor `json:"authors,omitempty"` Tags []string `json:"tags,omitempty"` Attachments []JSONAttachment `json:"attachments,omitempty"` } @@ -92,19 +93,21 @@ type JSONHub struct { // JSONFeed represents a syndication feed in the JSON Feed Version 1 format. // Matching the specification found here: https://jsonfeed.org/version/1. type JSONFeed struct { - Version string `json:"version"` - Title string `json:"title"` - HomePageUrl string `json:"home_page_url,omitempty"` - FeedUrl string `json:"feed_url,omitempty"` - Description string `json:"description,omitempty"` - UserComment string `json:"user_comment,omitempty"` - NextUrl string `json:"next_url,omitempty"` - Icon string `json:"icon,omitempty"` - Favicon string `json:"favicon,omitempty"` - Author *JSONAuthor `json:"author,omitempty"` - Expired *bool `json:"expired,omitempty"` - Hubs []*JSONHub `json:"hubs,omitempty"` - Items []*JSONItem `json:"items,omitempty"` + Version string `json:"version"` + Title string `json:"title"` + Language string `json:"language,omitempty"` + HomePageUrl string `json:"home_page_url,omitempty"` + FeedUrl string `json:"feed_url,omitempty"` + Description string `json:"description,omitempty"` + UserComment string `json:"user_comment,omitempty"` + NextUrl string `json:"next_url,omitempty"` + Icon string `json:"icon,omitempty"` + Favicon string `json:"favicon,omitempty"` + Author *JSONAuthor `json:"author,omitempty"` // deprecated in JSON Feed v1.1, keeping for backwards compatibility + Authors []*JSONAuthor `json:"authors,omitempty"` + Expired *bool `json:"expired,omitempty"` + Hubs []*JSONHub `json:"hubs,omitempty"` + Items []*JSONItem `json:"items,omitempty"` } // JSON is used to convert a generic Feed to a JSONFeed. @@ -139,9 +142,11 @@ func (f *JSON) JSONFeed() *JSONFeed { feed.HomePageUrl = f.Link.Href } if f.Author != nil { - feed.Author = &JSONAuthor{ + author := &JSONAuthor{ Name: f.Author.Name, } + feed.Author = author + feed.Authors = []*JSONAuthor{author} } for _, e := range f.Items { feed.Items = append(feed.Items, newJSONItem(e)) @@ -165,9 +170,11 @@ func newJSONItem(i *Item) *JSONItem { item.ExternalUrl = i.Source.Href } if i.Author != nil { - item.Author = &JSONAuthor{ + author := &JSONAuthor{ Name: i.Author.Name, } + item.Author = author + item.Authors = []*JSONAuthor{author} } if !i.Created.IsZero() { item.PublishedDate = &i.Created