Skip to content

Commit 63503c1

Browse files
committed
fix: rss 2.0 conformance and recommendations
1 parent 706545a commit 63503c1

File tree

1 file changed

+51
-23
lines changed

1 file changed

+51
-23
lines changed

server/rss_handler.go

Lines changed: 51 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,71 +7,99 @@ import (
77
"github.com/labstack/echo"
88
)
99

10+
type rssGUID struct {
11+
IsPermalink bool `xml:"isPermaLink,attr"`
12+
GUID string `xml:",chardata"`
13+
}
14+
1015
type rssItem struct {
11-
Title string `xml:"title"`
12-
GUID string `xml:"guid"`
13-
Description string `xml:"description"`
14-
Link string `xml:"link"`
15-
PubDate string `xml:"pubDate"`
16+
Title string `xml:"title"`
17+
GUID rssGUID `xml:"guid"`
18+
Description string `xml:"description"`
19+
Link string `xml:"link"`
20+
PubDate string `xml:"pubDate"`
21+
}
22+
23+
type rssAtomLink struct {
24+
HRef string `xml:"href,attr"`
25+
Rel string `xml:"rel,attr"`
26+
Type string `xml:"type,attr"`
1627
}
1728

1829
type rssChannel struct {
19-
Title string `xml:"title"`
20-
Description string `xml:"description"`
21-
Link string `xml:"link"`
30+
Title string `xml:"title"`
31+
Description string `xml:"description"`
32+
Link string `xml:"link"`
33+
AtomLink rssAtomLink `xml:"atom:link"`
34+
Items []rssItem `xml:"item"`
2235
}
2336

2437
type rssResponse struct {
2538
XMLName bool `xml:"rss"`
26-
Version int `xml:"version,attr"`
39+
Version string `xml:"version,attr"`
40+
Atom string `xml:"xmlns:atom,attr"`
2741
Channel rssChannel `xml:"channel"`
28-
Items []rssItem `xml:"item"`
2942
}
3043

3144
func RSSHandler(db *Database) echo.HandlerFunc {
3245
return func(c echo.Context) error {
3346
activity, _ := db.Activity(c.QueryParam("next"), 50)
3447
response := rssResponse{
35-
Version: 2,
48+
Version: "2.0",
49+
Atom: "http://www.w3.org/2005/Atom",
3650
Channel: rssChannel{
3751
Title: "GGG Tracker",
3852
Description: "Latest activity from Grinding Gear Games",
3953
Link: AbsoluteURL(c, ""),
54+
AtomLink: rssAtomLink{
55+
HRef: AbsoluteURL(c, "/rss"),
56+
Rel: "self",
57+
Type: "application/rss+xml",
58+
},
4059
},
4160
}
4261
for _, a := range activity {
4362
switch a.(type) {
4463
case *ForumPost:
4564
post := a.(*ForumPost)
46-
response.Items = append(response.Items, rssItem{
47-
Title: post.Poster + " - " + post.ThreadTitle,
48-
Link: post.PostURL(),
49-
GUID: fmt.Sprintf("poe-forum-post-%v", post.Id),
65+
response.Channel.Items = append(response.Channel.Items, rssItem{
66+
Title: post.Poster + " - " + post.ThreadTitle,
67+
Link: post.PostURL(),
68+
GUID: rssGUID{
69+
IsPermalink: false,
70+
GUID: fmt.Sprintf("poe-forum-post-%v", post.Id),
71+
},
5072
Description: post.BodyHTML,
5173
PubDate: post.Time.Format(time.RFC1123Z),
5274
})
5375
case *RedditComment:
5476
comment := a.(*RedditComment)
55-
response.Items = append(response.Items, rssItem{
56-
Title: comment.Author + " - " + comment.PostTitle,
57-
Link: comment.CommentURL(),
58-
GUID: "reddit-comment-" + comment.Id,
77+
response.Channel.Items = append(response.Channel.Items, rssItem{
78+
Title: comment.Author + " - " + comment.PostTitle,
79+
Link: comment.CommentURL(),
80+
GUID: rssGUID{
81+
IsPermalink: false,
82+
GUID: "reddit-comment-" + comment.Id,
83+
},
5984
Description: comment.BodyHTML,
6085
PubDate: comment.Time.Format(time.RFC1123Z),
6186
})
6287
case *RedditPost:
6388
post := a.(*RedditPost)
6489
item := rssItem{
65-
Title: post.Author + " - " + post.Title,
66-
Link: "https://www.reddit.com" + post.Permalink,
67-
GUID: "reddit-post-" + post.Id,
90+
Title: post.Author + " - " + post.Title,
91+
Link: "https://www.reddit.com" + post.Permalink,
92+
GUID: rssGUID{
93+
IsPermalink: false,
94+
GUID: "reddit-post-" + post.Id,
95+
},
6896
Description: post.BodyHTML,
6997
PubDate: post.Time.Format(time.RFC1123Z),
7098
}
7199
if item.Description == "" {
72100
item.Description = "<a href=\"" + post.URL + "\">" + post.URL + "</a>"
73101
}
74-
response.Items = append(response.Items, item)
102+
response.Channel.Items = append(response.Channel.Items, item)
75103
}
76104
}
77105
return c.XML(200, response)

0 commit comments

Comments
 (0)