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
|
func generateRSS(feed Feed) []byte {
rss := `<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">`
rss += `<channel>`
rss += fmt.Sprintf(`<title><![CDATA[%s]]></title>`, feed.Podcast.Title)
rss += fmt.Sprintf(`<description><![CDATA[%s]]></description>`, feed.Podcast.Description)
rss += fmt.Sprintf(`<link>%s</link>`, feed.Podcast.Link)
rss += fmt.Sprintf(`<image><url>%s</url><title>%s</title><link>%s</link></image>`, feed.Podcast.Image.URL, feed.Podcast.Image.Title, feed.Podcast.Image.Link)
rss += fmt.Sprintf(`<generator>%s</generator>`, "{YOUR_DOMAIN}")
rss += fmt.Sprintf(`<lastBuildData>%s</lastBuildData>`, feed.Podcast.LastBuildDate)
rss += fmt.Sprint(`<atom:link href="https://{YOUR_DOMAIN}/feed.rss" rel="self" type="application/rss+xml"/>`)
rss += fmt.Sprintf(`<author><![CDATA[%s]]></author>`, feed.Podcast.Author)
rss += fmt.Sprintf(`<copyright><![CDATA[%s]]></copyright>`, feed.Podcast.Author)
rss += fmt.Sprintf("<language>%s</language>", feed.Podcast.Language)
rss += fmt.Sprintf(`<category><![CDATA[%s]]></category>`, feed.Podcast.CategoryMain)
rss += fmt.Sprintf(`<category><![CDATA[%s]]></category>`, feed.Podcast.CategorySub)
rss += fmt.Sprintf(`<itunes:author>%s</itunes:author>`, feed.Podcast.Author)
rss += fmt.Sprintf(`<itunes:summary><![CDATA[%s]]></itunes:summary>`, feed.Podcast.Description)
rss += fmt.Sprintf(`<itunes:image href="%s"/>`, feed.Podcast.Image.URL)
rss += fmt.Sprintf(`<itunes:type>%s</itunes:type>`, feed.Podcast.Type)
rss += fmt.Sprint(`<itunes:owner>`)
rss += fmt.Sprintf(`<itunes:name><![CDATA[%s]]></itunes:name>`, feed.Podcast.Author)
rss += fmt.Sprintf(`<itunes:email>%s</itunes:email>`, feed.Podcast.Email)
rss += fmt.Sprintf(`</itunes:owner>`)
rss += fmt.Sprintf(`<itunes:explicit>%s</itunes:explicit>`, feed.Podcast.Explicit)
rss += fmt.Sprintf(`<itunes:category text="%s"> <itunes:category text="%s" /></itunes:category>`, feed.Podcast.CategoryMain, feed.Podcast.CategorySub)
for _, v := range feed.Podcast.Episodes {
rss += fmt.Sprintf(`<item>`)
rss += fmt.Sprintf(`<title><![CDATA[%s]]></title>`, v.Title)
rss += fmt.Sprintf(`<description><![CDATA[%s]]></description>`, v.Description)
rss += fmt.Sprintf(`<link>%s</link>`, v.Link)
rss += fmt.Sprintf(`<guid>%s</guid>`, strings.Split(v.Link, "/")[:len(strings.Split(v.Link, "/"))-1])
rss += fmt.Sprintf(`<dc:creator><![CDATA[%s]]></dc:creator>`, v.Creator)
rss += fmt.Sprintf(`<pubDate>%s</pubDate>`, feed.Podcast.LastBuildDate)
rss += fmt.Sprintf(`<enclosure url="%s" length="%s" type="audio/mpeg"/>`, v.Audio, v.Duration)
rss += fmt.Sprintf(`<itunes:summary><![CDATA[%s]]></itunes:summary>`, v.Description)
rss += fmt.Sprintf(`<itunes:explicit>%s</itunes:explicit>`, v.Explicit)
rss += fmt.Sprintf(`<itunes:duration>%s</itunes:duration>`, v.Duration)
rss += fmt.Sprintf(`<itunes:image href="%s"/>`, v.Image)
rss += fmt.Sprintf(`<itunes:episode>%d</itunes:episode>`, v.Episode)
rss += fmt.Sprintf(`<itunes:episodeType>%s</itunes:episodeType>`, v.Type)
rss += fmt.Sprintf(`</item>`)
}
rss += `</channel></rss>`
return []byte(rss)
}
|