Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 23 additions & 16 deletions atom.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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,
}
Expand Down
14 changes: 8 additions & 6 deletions consume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down
2 changes: 1 addition & 1 deletion feed.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type Item struct {

type Feed struct {
Title string
Link *Link
Links []*Link
Description string
Author *Author
Updated time.Time
Expand Down
9 changes: 5 additions & 4 deletions feed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ var atomOutput = `<?xml version="1.0" encoding="UTF-8"?><feed xmlns="http://www.
<updated>2013-01-16T21:52:35-05:00</updated>
<rights>This work is copyright © Benjamin Button</rights>
<subtitle>discussion about tech, footie, photos</subtitle>
<link href="http://jmoiron.net/blog"></link>
<link href="http://jmoiron.net/blog" rel="alternate"></link>
<link href="http://jmoiron.net/feed.atom" rel="self"></link>
<author>
<name>Jason Moiron</name>
<email>[email protected]</email>
Expand Down Expand Up @@ -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: "[email protected]"},
Created: now,
Expand Down Expand Up @@ -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: "[email protected]"},
Created: now,
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions json.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
9 changes: 5 additions & 4 deletions rss.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading