Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't create an empty <summary> in Atom feeds #83

Merged
merged 3 commits into from
Aug 17, 2023
Merged
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
8 changes: 5 additions & 3 deletions atom.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ type Atom struct {

func newAtomEntry(i *Item) *AtomEntry {
id := i.Id
// assume the description is html
s := &AtomSummary{Content: i.Description, Type: "html"}

if len(id) == 0 {
// if there's no id set, try to create one, either from data or just a uuid
Expand Down Expand Up @@ -119,7 +117,11 @@ func newAtomEntry(i *Item) *AtomEntry {
Links: []AtomLink{{Href: i.Link.Href, Rel: link_rel, Type: i.Link.Type}},
Id: id,
Updated: anyTimeFormat(time.RFC3339, i.Updated, i.Created),
Summary: s,
}

// if there's a description, assume it's html
if len(i.Description) > 0 {
x.Summary = &AtomSummary{Content: i.Description, Type: "html"}
}

// if there's a content, assume it's html
Expand Down
32 changes: 27 additions & 5 deletions feed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ var atomOutput = `<?xml version="1.0" encoding="UTF-8"?><feed xmlns="http://www.
<link href="http://example.com/strings" rel="alternate"></link>
<summary type="html">How to use things like %s, %v, %d, etc.</summary>
</entry>
<entry>
<title>Go Proverb #1</title>
<updated>2013-01-16T21:52:35-05:00</updated>
<id>tag:go-proverbs.github.io,2013-01-16:/</id>
<content type="html">Don&#39;t communicate by sharing memory, share memory by communicating.</content>
<link href="https://go-proverbs.github.io/" rel="alternate"></link>
</entry>
</feed>`

var rssOutput = `<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
Expand Down Expand Up @@ -103,6 +110,13 @@ var rssOutput = `<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:
<description>How to use things like %s, %v, %d, etc.</description>
<pubDate>Wed, 16 Jan 2013 21:52:35 -0500</pubDate>
</item>
<item>
<title>Go Proverb #1</title>
<link>https://go-proverbs.github.io/</link>
<description></description>
<content:encoded><![CDATA[Don't communicate by sharing memory, share memory by communicating.]]></content:encoded>
<pubDate>Wed, 16 Jan 2013 21:52:35 -0500</pubDate>
</item>
</channel>
</rss>`

Expand Down Expand Up @@ -154,6 +168,13 @@ var jsonOutput = `{
"title": "String formatting in Go",
"summary": "How to use things like %s, %v, %d, etc.",
"date_published": "2013-01-16T21:52:35-05:00"
},
{
"id": "",
"url": "https://go-proverbs.github.io/",
"title": "Go Proverb #1",
"content_html": "Don't communicate by sharing memory, share memory by communicating.",
"date_published": "2013-01-16T21:52:35-05:00"
}
]
}`
Expand Down Expand Up @@ -209,6 +230,12 @@ func TestFeed(t *testing.T) {
Link: &Link{Href: "http://example.com/strings"},
Description: "How to use things like %s, %v, %d, etc.",
Created: now,
},
{
Title: "Go Proverb #1",
Link: &Link{Href: "https://go-proverbs.github.io/"},
Content: "Don't communicate by sharing memory, share memory by communicating.",
Created: now,
}}

atom, err := feed.ToAtom()
Expand Down Expand Up @@ -273,35 +300,30 @@ var atomOutputSorted = `<?xml version="1.0" encoding="UTF-8"?><feed xmlns="http:
<updated>2013-01-18T21:52:35-05:00</updated>
<id>tag:jmoiron.net,2013-01-18:/blog/limiting-concurrency-in-go/</id>
<link href="http://jmoiron.net/blog/limiting-concurrency-in-go/" rel="alternate"></link>
<summary type="html"></summary>
</entry>
<entry>
<title>Logic-less Template Redux</title>
<updated>2013-01-17T21:52:35-05:00</updated>
<id>tag:jmoiron.net,2013-01-17:/blog/logicless-template-redux/</id>
<link href="http://jmoiron.net/blog/logicless-template-redux/" rel="alternate"></link>
<summary type="html"></summary>
</entry>
<entry>
<title>Idiomatic Code Reuse in Go</title>
<updated>2013-01-17T09:52:35-05:00</updated>
<id>tag:jmoiron.net,2013-01-17:/blog/idiomatic-code-reuse-in-go/</id>
<link href="http://jmoiron.net/blog/idiomatic-code-reuse-in-go/" rel="alternate"></link>
<summary type="html"></summary>
</entry>
<entry>
<title>Never Gonna Give You Up Mp3</title>
<updated>2013-01-17T07:52:35-05:00</updated>
<id>tag:example.com,2013-01-17:/RickRoll.mp3</id>
<link href="http://example.com/RickRoll.mp3" rel="alternate"></link>
<summary type="html"></summary>
</entry>
<entry>
<title>String formatting in Go</title>
<updated>2013-01-16T21:52:35-05:00</updated>
<id>tag:example.com,2013-01-16:/strings</id>
<link href="http://example.com/strings" rel="alternate"></link>
<summary type="html"></summary>
</entry>
</feed>`

Expand Down