Make RssFeed the channel object, add a lot more fields to the underlying atom implementation

This commit is contained in:
Jason Moiron
2013-01-16 20:53:51 -05:00
parent 6788dd66c9
commit 09ecc7cb78
3 changed files with 62 additions and 37 deletions
+53 -31
View File
@@ -11,20 +11,35 @@ import (
const ns = "http://www.w3.org/2005/Atom"
type AtomPerson struct {
Name string `xml:"name,omitempty"`
Uri string `xml:"uri,omitempty"`
Email string `xml:"email,omitempty"`
}
type AtomSummary struct {
S string `xml:",chardata"`
Type string `xml:"type,attr"`
Content string `xml:",chardata"`
Type string `xml:"type,attr"`
}
type AtomAuthor struct {
XMLName xml.Name `xml:"author"`
AtomPerson
}
type AtomContributor struct {
XMLName xml.Name `xml:"contributor"`
AtomPerson
}
type AtomEntry struct {
XMLName xml.Name `xml:"entry"`
Title string `xml:"title"`
Link *AtomLink
Updated string `xml:"updated"`
Id string `xml:"id"`
Summary *AtomSummary `xml:"summary,omitempty"`
AuthorName string `xml:"author>name,omitempty"`
AuthorEmail string `xml:"author>email,omitempty"`
XMLName xml.Name `xml:"entry"`
Title string `xml:"title"`
Link *AtomLink
Updated string `xml:"updated"`
Id string `xml:"id"`
Summary *AtomSummary `xml:"summary,omitempty"`
Author *AtomAuthor
}
type AtomLink struct {
@@ -34,14 +49,19 @@ type AtomLink struct {
}
type AtomFeed struct {
XMLName xml.Name `xml:"feed"`
Ns string `xml:"xmlns,attr"`
Title string `xml:"title"`
Link *AtomLink
Id string `xml:"id,omitempty"`
Updated string `xml:"updated"`
Summary string `xml:"summary,omitempty"`
Entries []*AtomEntry
XMLName xml.Name `xml:"feed"`
Xmlns string `xml:"xmlns,attr"`
Category string `xml:"category,omitempty"`
Icon string `xml:"icon"`
Logo string `xml:"logo"`
Rights string `xml:"rights,omitempty"`
Title string `xml:"title"`
Subtitle string `xml:"subtitle,omitempty"`
Id string `xml:"id,omitempty"`
Updated string `xml:"updated"`
Link *AtomLink
Contributor *AtomContributor
Entries []*AtomEntry
}
type Atom struct {
@@ -70,14 +90,16 @@ func newAtomEntry(i *Item) *AtomEntry {
if i.Author != nil {
name, email = i.Author.Name, i.Author.Email
}
x := &AtomEntry{
Title: i.Title,
Link: &AtomLink{Href: i.Link.Href, Rel: i.Link.Rel},
Summary: s,
Id: id,
Updated: anyTimeFormat(time.RFC3339, i.Updated, i.Created),
AuthorName: name,
AuthorEmail: email,
Title: i.Title,
Link: &AtomLink{Href: i.Link.Href, Rel: i.Link.Rel},
Summary: s,
Id: id,
Updated: anyTimeFormat(time.RFC3339, i.Updated, i.Created),
}
if len(name) > 0 || len(email) > 0 {
x.Author = &AtomAuthor{AtomPerson: AtomPerson{Name: name, Email: email}}
}
return x
}
@@ -85,12 +107,12 @@ func newAtomEntry(i *Item) *AtomEntry {
func (a *Atom) FeedXml() interface{} {
updated := anyTimeFormat(time.RFC3339, a.Updated, a.Created)
feed := &AtomFeed{
Ns: ns,
Title: a.Title,
Link: &AtomLink{Href: a.Link.Href, Rel: a.Link.Rel},
Summary: a.Description,
Id: a.Link.Href,
Updated: updated,
Xmlns: ns,
Title: a.Title,
Link: &AtomLink{Href: a.Link.Href, Rel: a.Link.Rel},
Subtitle: a.Description,
Id: a.Link.Href,
Updated: updated,
}
for _, e := range a.Items {
feed.Entries = append(feed.Entries, newAtomEntry(e))
+2 -1
View File
@@ -29,10 +29,11 @@ type Feed struct {
Description string
Author *Author
Updated time.Time
Created time.Time
Id string
Subtitle string
Created time.Time
Items []*Item
Copyright string
}
func (f *Feed) Add(item *Item) {
+7 -5
View File
@@ -7,13 +7,15 @@ import (
"time"
)
type RssFeed struct {
// private wrapper around the RssFeed which gives us the <rss>..</rss> xml
type rssFeedXml struct {
XMLName xml.Name `xml:"rss"`
Version string `xml:"version,attr"`
Channel *RssChannel
Channel *RssFeed
}
type RssChannel struct {
// rss feed object which
type RssFeed struct {
XMLName xml.Name `xml:"channel"`
Title string `xml:"title"` // required
Link string `xml:"link"` // required
@@ -81,9 +83,9 @@ func (r *Rss) FeedXml() interface{} {
if len(r.Author.Name) > 0 {
author = fmt.Sprintf("%s (%s)", r.Author.Email, r.Author.Name)
}
feed := &RssFeed{
feed := &rssFeedXml{
Version: "2.0",
Channel: &RssChannel{
Channel: &RssFeed{
Title: r.Title,
Link: r.Link.Href,
Description: r.Description,