From 087409c2e19f1495a14c7acbfae4993944ac2174 Mon Sep 17 00:00:00 2001 From: Vabd Date: Tue, 20 Mar 2018 10:20:20 +0100 Subject: [PATCH] Improve content appending in item --- atom.go | 12 +++++------- rss.go | 10 +++------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/atom.go b/atom.go index 61a59f8..5f483fe 100644 --- a/atom.go +++ b/atom.go @@ -92,12 +92,6 @@ func newAtomEntry(i *Item) *AtomEntry { // assume the description is html s := &AtomSummary{Content: i.Description, Type: "html"} - // if there's a content, assume it's html - var c *AtomContent - if len(i.Content) > 0 { - c = &AtomContent{Content: i.Content, Type: "html"} - } - if len(id) == 0 { // if there's no id set, try to create one, either from data or just a uuid if len(i.Link.Href) > 0 && (!i.Created.IsZero() || !i.Updated.IsZero()) { @@ -123,12 +117,16 @@ func newAtomEntry(i *Item) *AtomEntry { x := &AtomEntry{ Title: i.Title, Links: []AtomLink{{Href: i.Link.Href, Rel: link_rel, Type: i.Link.Type}}, - Content: c, Id: id, Updated: anyTimeFormat(time.RFC3339, i.Updated, i.Created), Summary: s, } + // if there's a content, assume it's html + if len(i.Content) > 0 { + x.Content = &AtomContent{Content: i.Content, Type: "html"} + } + if i.Enclosure != nil && link_rel != "enclosure" { x.Links = append(x.Links, AtomLink{Href: i.Enclosure.Url, Rel: "enclosure", Type: i.Enclosure.Type, Length: i.Enclosure.Length}) } diff --git a/rss.go b/rss.go index 8a6e711..c560b3f 100644 --- a/rss.go +++ b/rss.go @@ -92,19 +92,15 @@ type Rss struct { // create a new RssItem with a generic Item struct's data func newRssItem(i *Item) *RssItem { - // append an encoded content if one is provided - var c *RssContent - if len(i.Content) > 0 { - c = &RssContent{Content: i.Content} - } - item := &RssItem{ Title: i.Title, Link: i.Link.Href, Description: i.Description, Guid: i.Id, PubDate: anyTimeFormat(time.RFC1123Z, i.Created, i.Updated), - Content: c, + } + if len(i.Content) > 0 { + item.Content = &RssContent{Content: i.Content} } if i.Source != nil { item.Source = i.Source.Href