This repository has been archived by the owner on Oct 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
rss.go
62 lines (56 loc) · 1.91 KB
/
rss.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
// http://cyber.harvard.edu/rss/rss.html
type RSS struct {
XMLName string `xml:"rss"`
Version string `xml:"version,attr"`
NSDublinCore string `xml:"xmlns:dc,attr"`
NSAtom string `xml:"xmlns:atom,attr"`
Title string `xml:"channel>title"`
Link string `xml:"channel>link"`
Description string `xml:"channel>description"`
Docs string `xml:"channel>docs"`
Generator string `xml:"channel>generator"`
LastBuildDate string `xml:"channel>lastBuildDate"`
AtomLink AtomLink `xml:"channel>atom:link"`
Items []RSSItem `xml:"channel>item"`
}
type RSSPermalink struct {
Value string `xml:",chardata"`
IsPermaLink string `xml:"isPermaLink,attr"`
}
type RSSItem struct {
Title CDATA `xml:"title"`
Description CDATA `xml:"description"`
Published string `xml:"pubDate"`
Link string `xml:"link"`
Author string `xml:"dc:creator"`
Comments string `xml:"comments"`
Permalink RSSPermalink `xml:"guid"`
}
func NewRSS(results *AlgoliaSearchResponse, op *OutputParams) *RSS {
rss := RSS{
Version: "2.0",
NSAtom: NSAtom,
NSDublinCore: NSDublinCore,
Title: op.Title,
Link: op.Link,
Description: "Hacker News RSS",
Docs: "https://hnrss.org/",
Generator: "go-hnrss " + buildString,
LastBuildDate: Timestamp("rss", UTCNow()),
AtomLink: AtomLink{op.SelfLink, "self", "application/rss+xml"},
}
for _, hit := range results.Hits {
item := RSSItem{
Title: CDATA{hit.GetTitle()},
Link: hit.GetURL(op.LinkTo),
Description: CDATA{hit.GetDescription()},
Author: hit.Author,
Comments: hit.GetPermalink(),
Published: Timestamp("rss", hit.GetCreatedAt()),
Permalink: RSSPermalink{hit.GetPermalink(), "false"},
}
rss.Items = append(rss.Items, item)
}
return &rss
}