mirror of
https://github.com/miniflux/v2.git
synced 2025-09-15 18:57:04 +00:00
feat: populate feed description automatically
This commit is contained in:
parent
5920e02562
commit
8142268799
9 changed files with 83 additions and 11 deletions
|
@ -39,6 +39,10 @@ type Atom10Feed struct {
|
|||
// atom:feed elements MUST contain exactly one atom:title element.
|
||||
Title Atom10Text `xml:"http://www.w3.org/2005/Atom title"`
|
||||
|
||||
// The "atom:subtitle" element is a Text construct that
|
||||
// contains a human-readable description or subtitle for the feed.
|
||||
Subtitle Atom10Text `xml:"http://www.w3.org/2005/Atom subtitle"`
|
||||
|
||||
// The "atom:author" element is a Person construct that indicates the
|
||||
// author of the entry or feed.
|
||||
//
|
||||
|
|
|
@ -55,6 +55,9 @@ func (a *Atom10Adapter) BuildFeed(baseURL string) *model.Feed {
|
|||
feed.Title = feed.SiteURL
|
||||
}
|
||||
|
||||
// Populate the feed description.
|
||||
feed.Description = a.atomFeed.Subtitle.Body()
|
||||
|
||||
// Populate the feed icon.
|
||||
if a.atomFeed.Icon != "" {
|
||||
if absoluteIconURL, err := urllib.AbsoluteURL(feed.SiteURL, a.atomFeed.Icon); err == nil {
|
||||
|
|
|
@ -82,6 +82,29 @@ func TestParseAtomSample(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestParseFeedWithSubtitle(t *testing.T) {
|
||||
data := `<?xml version="1.0" encoding="utf-8"?>
|
||||
<feed xmlns="http://www.w3.org/2005/Atom">
|
||||
<title>Example Feed</title>
|
||||
<subtitle>This is a subtitle</subtitle>
|
||||
<link href="http://example.org/"/>
|
||||
<updated>2003-12-13T18:30:02Z</updated>
|
||||
<author>
|
||||
<name>John Doe</name>
|
||||
</author>
|
||||
<id>urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6</id>
|
||||
</feed>`
|
||||
|
||||
feed, err := Parse("http://example.org/feed.xml", bytes.NewReader([]byte(data)), "10")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if feed.Description != "This is a subtitle" {
|
||||
t.Errorf("Incorrect description, got: %s", feed.Description)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseFeedWithoutTitle(t *testing.T) {
|
||||
data := `<?xml version="1.0" encoding="utf-8"?>
|
||||
<feed xmlns="http://www.w3.org/2005/Atom">
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue