Skip to content

Commit

Permalink
Add the isPermaLink attribute to guid in RSS (#107)
Browse files Browse the repository at this point in the history
Adds the optional attribute from the `guid` RSS spec:
https://www.rssboard.org/rss-specification#ltguidgtSubelementOfLtitemgt

This is a breaking change to the `RssItem` struct as `Guid` is now a
struct, not a string.

- Related Issue go-gitea/gitea#28734
- Closes #78
- Closes #109 

Signed-off-by: Yarden Shoham <git@yardenshoham.com>
  • Loading branch information
yardenshoham committed Jun 17, 2024
1 parent 51ef1e4 commit eb2fb30
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
20 changes: 10 additions & 10 deletions consume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var testRssFeedXML = RssFeedXml{
Category: "",
Comments: "",
Enclosure: (*RssEnclosure)(nil),
Guid: "http://example.com/test/1540941720",
Guid: &RssGuid{XMLName: xml.Name{Local: "guid"}, Id: "http://example.com/test/1540941720", IsPermaLink: "true"},
PubDate: "Tue, 30 Oct 2018 23:22:00 GMT",
Source: "",
},
Expand All @@ -60,7 +60,7 @@ var testRssFeedXML = RssFeedXml{
Category: "",
Comments: "",
Enclosure: (*RssEnclosure)(nil),
Guid: "http://example.com/test/1540941660",
Guid: &RssGuid{XMLName: xml.Name{Local: "guid"}, Id: "http://example.com/test/1540941660", IsPermaLink: "true"},
PubDate: "Tue, 30 Oct 2018 23:21:00 GMT",
Source: "",
},
Expand All @@ -74,7 +74,7 @@ var testRssFeedXML = RssFeedXml{
Category: "",
Comments: "",
Enclosure: (*RssEnclosure)(nil),
Guid: "http://example.com/test/1540941600",
Guid: &RssGuid{XMLName: xml.Name{Local: "guid"}, Id: "http://example.com/test/1540941600", IsPermaLink: "true"},
PubDate: "Tue, 30 Oct 2018 23:20:00 GMT",
Source: "",
},
Expand All @@ -88,7 +88,7 @@ var testRssFeedXML = RssFeedXml{
Category: "",
Comments: "",
Enclosure: (*RssEnclosure)(nil),
Guid: "http://example.com/test/1540941540",
Guid: &RssGuid{XMLName: xml.Name{Local: "guid"}, Id: "http://example.com/test/1540941540", IsPermaLink: "true"},
PubDate: "Tue, 30 Oct 2018 23:19:00 GMT",
Source: "",
},
Expand All @@ -102,7 +102,7 @@ var testRssFeedXML = RssFeedXml{
Category: "",
Comments: "",
Enclosure: (*RssEnclosure)(nil),
Guid: "http://example.com/test/1540941480",
Guid: &RssGuid{XMLName: xml.Name{Local: "guid"}, Id: "http://example.com/test/1540941480", IsPermaLink: "true"},
PubDate: "Tue, 30 Oct 2018 23:18:00 GMT",
Source: "",
},
Expand All @@ -116,7 +116,7 @@ var testRssFeedXML = RssFeedXml{
Category: "",
Comments: "",
Enclosure: (*RssEnclosure)(nil),
Guid: "http://example.com/test/1540941420",
Guid: &RssGuid{XMLName: xml.Name{Local: "guid"}, Id: "http://example.com/test/1540941420", IsPermaLink: "true"},
PubDate: "Tue, 30 Oct 2018 23:17:00 GMT",
Source: "",
},
Expand All @@ -130,7 +130,7 @@ var testRssFeedXML = RssFeedXml{
Category: "",
Comments: "",
Enclosure: (*RssEnclosure)(nil),
Guid: "http://example.com/test/1540941360",
Guid: &RssGuid{XMLName: xml.Name{Local: "guid"}, Id: "http://example.com/test/1540941360", IsPermaLink: "true"},
PubDate: "Tue, 30 Oct 2018 23:16:00 GMT",
Source: "",
},
Expand All @@ -144,7 +144,7 @@ var testRssFeedXML = RssFeedXml{
Category: "",
Comments: "",
Enclosure: (*RssEnclosure)(nil),
Guid: "http://example.com/test/1540941300",
Guid: &RssGuid{XMLName: xml.Name{Local: "guid"}, Id: "http://example.com/test/1540941300", IsPermaLink: "true"},
PubDate: "Tue, 30 Oct 2018 23:15:00 GMT",
Source: "",
},
Expand All @@ -158,7 +158,7 @@ var testRssFeedXML = RssFeedXml{
Category: "",
Comments: "",
Enclosure: (*RssEnclosure)(nil),
Guid: "http://example.com/test/1540941240",
Guid: &RssGuid{XMLName: xml.Name{Local: "guid"}, Id: "http://example.com/test/1540941240", IsPermaLink: "true"},
PubDate: "Tue, 30 Oct 2018 23:14:00 GMT",
Source: "",
},
Expand All @@ -172,7 +172,7 @@ var testRssFeedXML = RssFeedXml{
Category: "",
Comments: "",
Enclosure: (*RssEnclosure)(nil),
Guid: "http://example.com/test/1540941180",
Guid: &RssGuid{XMLName: xml.Name{Local: "guid"}, Id: "http://example.com/test/1540941180", IsPermaLink: "true"},
PubDate: "Tue, 30 Oct 2018 23:13:00 GMT",
Source: "",
},
Expand Down
1 change: 1 addition & 0 deletions feed.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type Item struct {
Author *Author
Description string // used as description in rss, summary in atom
Id string // used as guid in rss, id in atom
IsPermaLink string // an optional parameter for guid in rss
Updated time.Time
Created time.Time
Enclosure *Enclosure
Expand Down
17 changes: 13 additions & 4 deletions rss.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ type RssItem struct {
Category string `xml:"category,omitempty"`
Comments string `xml:"comments,omitempty"`
Enclosure *RssEnclosure
Guid string `xml:"guid,omitempty"` // Id used
PubDate string `xml:"pubDate,omitempty"` // created or updated
Source string `xml:"source,omitempty"`
Guid *RssGuid // Id used
PubDate string `xml:"pubDate,omitempty"` // created or updated
Source string `xml:"source,omitempty"`
}

type RssEnclosure struct {
Expand All @@ -87,6 +87,13 @@ type RssEnclosure struct {
Type string `xml:"type,attr"`
}

type RssGuid struct {
//RSS 2.0 <guid isPermaLink="true">http://inessential.com/2002/09/01.php#a2</guid>
XMLName xml.Name `xml:"guid"`
Id string `xml:",chardata"`
IsPermaLink string `xml:"isPermaLink,attr,omitempty"` // "true", "false", or an empty string
}

type Rss struct {
*Feed
}
Expand All @@ -96,9 +103,11 @@ func newRssItem(i *Item) *RssItem {
item := &RssItem{
Title: i.Title,
Description: i.Description,
Guid: i.Id,
PubDate: anyTimeFormat(time.RFC1123Z, i.Created, i.Updated),
}
if i.Id != "" {
item.Guid = &RssGuid{Id: i.Id, IsPermaLink: i.IsPermaLink}
}
if i.Link != nil {
item.Link = i.Link.Href
}
Expand Down

0 comments on commit eb2fb30

Please sign in to comment.