diff --git a/atom.go b/atom.go index 73de995..f3b740c 100644 --- a/atom.go +++ b/atom.go @@ -67,17 +67,17 @@ type AtomLink struct { } type AtomFeed struct { - XMLName xml.Name `xml:"feed"` - Xmlns string `xml:"xmlns,attr"` - Title string `xml:"title"` // required - Id string `xml:"id"` // required - Updated string `xml:"updated"` // required - Category string `xml:"category,omitempty"` - Icon string `xml:"icon,omitempty"` - Logo string `xml:"logo,omitempty"` - Rights string `xml:"rights,omitempty"` // copyright used - Subtitle string `xml:"subtitle,omitempty"` - Link *AtomLink + XMLName xml.Name `xml:"feed"` + Xmlns string `xml:"xmlns,attr"` + Title string `xml:"title"` // required + Id string `xml:"id"` // required + Updated string `xml:"updated"` // required + Category string `xml:"category,omitempty"` + Icon string `xml:"icon,omitempty"` + Logo string `xml:"logo,omitempty"` + Rights string `xml:"rights,omitempty"` // copyright used + Subtitle string `xml:"subtitle,omitempty"` + Links []*AtomLink `xml:"link,omitempty"` Author *AtomAuthor `xml:"author,omitempty"` Contributor *AtomContributor Entries []*AtomEntry `xml:"entry"` @@ -145,16 +145,23 @@ func newAtomEntry(i *Item) *AtomEntry { // create a new AtomFeed with a generic Feed struct's data func (a *Atom) AtomFeed() *AtomFeed { updated := anyTimeFormat(time.RFC3339, a.Updated, a.Created) - link := a.Link - if link == nil { - link = &Link{} + + var atomLinks []*AtomLink + for _, link := range a.Links { + atomLinks = append(atomLinks, &AtomLink{Href: link.Href, Rel: link.Rel}) } + + var id string + if a.Links != nil { + id = a.Links[0].Href + } + feed := &AtomFeed{ Xmlns: ns, Title: a.Title, - Link: &AtomLink{Href: link.Href, Rel: link.Rel}, + Links: atomLinks, Subtitle: a.Description, - Id: link.Href, + Id: id, Updated: updated, Rights: a.Copyright, } diff --git a/consume_test.go b/consume_test.go index 5abe4d1..3367cc7 100644 --- a/consume_test.go +++ b/consume_test.go @@ -191,12 +191,14 @@ var testAtomFeedXML = AtomFeed{ Logo: "", Rights: "", Subtitle: "", - Link: &AtomLink{ - XMLName: xml.Name{Space: "", Local: "link"}, - Href: "", - Rel: "", - Type: "", - Length: "", + Links: []*AtomLink{ + { + XMLName: xml.Name{Space: "", Local: "link"}, + Href: "", + Rel: "", + Type: "", + Length: "", + }, }, Author: &AtomAuthor{ XMLName: xml.Name{Space: "", Local: "author"}, diff --git a/feed.go b/feed.go index 929c226..7d42b5d 100644 --- a/feed.go +++ b/feed.go @@ -41,7 +41,7 @@ type Item struct { type Feed struct { Title string - Link *Link + Links []*Link Description string Author *Author Updated time.Time diff --git a/feed_test.go b/feed_test.go index 837cfa6..2ef804d 100644 --- a/feed_test.go +++ b/feed_test.go @@ -12,7 +12,8 @@ var atomOutput = ` + + Jason Moiron jmoiron@jmoiron.net @@ -199,7 +200,7 @@ func TestFeed(t *testing.T) { feed := &Feed{ Title: "jmoiron.net blog", - Link: &Link{Href: "http://jmoiron.net/blog"}, + Links: []*Link{{Rel: "alternate", Href: "http://jmoiron.net/blog"}, {Rel: "self", Href: "http://jmoiron.net/feed.atom"}}, Description: "discussion about tech, footie, photos", Author: &Author{Name: "Jason Moiron", Email: "jmoiron@jmoiron.net"}, Created: now, @@ -435,7 +436,7 @@ func TestFeedSorted(t *testing.T) { feed := &Feed{ Title: "jmoiron.net blog", - Link: &Link{Href: "http://jmoiron.net/blog"}, + Links: []*Link{{Href: "http://jmoiron.net/blog"}}, Description: "discussion about tech, footie, photos", Author: &Author{Name: "Jason Moiron", Email: "jmoiron@jmoiron.net"}, Created: now, @@ -529,7 +530,7 @@ func TestFeedNil(t *testing.T) { feed := &Feed{ Title: "jmoiron.net blog", - Link: nil, + Links: nil, Description: "discussion about tech, footie, photos", Author: nil, Created: now, diff --git a/json.go b/json.go index ae5deb7..7dda7de 100644 --- a/json.go +++ b/json.go @@ -138,8 +138,8 @@ func (f *JSON) JSONFeed() *JSONFeed { Description: f.Description, } - if f.Link != nil { - feed.HomePageUrl = f.Link.Href + if f.Links != nil { + feed.HomePageUrl = f.Links[0].Href } if f.Author != nil { author := &JSONAuthor{ diff --git a/rss.go b/rss.go index 9326cef..3bce6a0 100644 --- a/rss.go +++ b/rss.go @@ -146,13 +146,14 @@ func (r *Rss) RssFeed() *RssFeed { image = &RssImage{Url: r.Image.Url, Title: r.Image.Title, Link: r.Image.Link, Width: r.Image.Width, Height: r.Image.Height} } - var href string - if r.Link != nil { - href = r.Link.Href + var link string + if r.Links != nil { + link = r.Links[0].Href } + channel := &RssFeed{ Title: r.Title, - Link: href, + Link: link, Description: r.Description, ManagingEditor: author, PubDate: pub,