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

Add the isPermaLink attribute to guid in RSS #107

Merged
merged 1 commit into from
Jun 17, 2024
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
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 {
jaitaiwan marked this conversation as resolved.
Show resolved Hide resolved
//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
Loading