improve rss
This commit is contained in:
parent
e31dbeb18c
commit
d736679418
|
@ -19,10 +19,15 @@ type RSS struct {
|
|||
Channel RSSChannel `xml:"channel"`
|
||||
}
|
||||
|
||||
type RSSDescription struct {
|
||||
XMLName xml.Name `xml:"description"`
|
||||
Text string `xml:",cdata"`
|
||||
}
|
||||
|
||||
type RSSChannel struct {
|
||||
Title string `xml:"title"`
|
||||
Link string `xml:"link"`
|
||||
Description string `xml:"description"`
|
||||
Description RSSDescription `xml:"description"`
|
||||
Items []RSSItem `xml:"item"`
|
||||
}
|
||||
|
||||
|
@ -31,7 +36,7 @@ type RSSItem struct {
|
|||
Title string `xml:"title"`
|
||||
Link string `xml:"link"`
|
||||
PubDate string `xml:"pubDate"`
|
||||
Description string `xml:"description"`
|
||||
Description RSSDescription `xml:"description"`
|
||||
}
|
||||
|
||||
func RenderRSSFeed(config model.SiteConfig, entries []model.Entry) (string, error) {
|
||||
|
@ -41,25 +46,32 @@ func RenderRSSFeed(config model.SiteConfig, entries []model.Entry) (string, erro
|
|||
Channel: RSSChannel{
|
||||
Title: config.Title,
|
||||
Link: config.FullUrl,
|
||||
Description: config.SubTitle,
|
||||
Description: RSSDescription{
|
||||
Text: config.SubTitle,
|
||||
},
|
||||
Items: make([]RSSItem, 0),
|
||||
},
|
||||
}
|
||||
|
||||
for _, entry := range entries {
|
||||
content := entry.Content()
|
||||
url, _ := url.JoinPath(config.FullUrl, "/posts/", entry.ID(), "/")
|
||||
entryUrl, _ := url.JoinPath(config.FullUrl, "/posts/", url.PathEscape(entry.ID()), "/")
|
||||
|
||||
rss.Channel.Items = append(rss.Channel.Items, RSSItem{
|
||||
Guid: url,
|
||||
Guid: entryUrl,
|
||||
Title: entry.Title(),
|
||||
Link: url,
|
||||
Link: entryUrl,
|
||||
PubDate: entry.PublishedAt().Format(time.RFC1123Z),
|
||||
Description: string(content),
|
||||
Description: RSSDescription{
|
||||
Text: string(content),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
buf := new(bytes.Buffer)
|
||||
err := xml.NewEncoder(buf).Encode(rss)
|
||||
encoder := xml.NewEncoder(buf)
|
||||
encoder.Indent("", " ")
|
||||
err := encoder.Encode(rss)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue