Various fixes in RSS feed generation

- Prevent `.xml` generation for root section
- Remove redundant check for DisableRSS
- Fix permalinks for rel="alternate"
- Rename generated xml file to <type>/index.xml
- Add required description element in default template
- Make default RSS template validate on w3c (timezone format is still an issue)

Conflicts:
	hugolib/site.go
This commit is contained in:
Kartik Singhal 2014-11-16 20:11:07 +05:30 committed by spf13
parent a07dd5650e
commit 596d679386
3 changed files with 23 additions and 23 deletions

View file

@ -56,10 +56,10 @@ func TestRSSOutput(t *testing.T) {
t.Fatalf("Unable to RenderHomePage: %s", err) t.Fatalf("Unable to RenderHomePage: %s", err)
} }
file, err := hugofs.DestinationFS.Open("rss.xml") file, err := hugofs.DestinationFS.Open("index.xml")
if err != nil { if err != nil {
t.Fatalf("Unable to locate: %s", "rss.xml") t.Fatalf("Unable to locate: %s", "index.xml")
} }
rss := helpers.ReaderToBytes(file) rss := helpers.ReaderToBytes(file)

View file

@ -868,14 +868,15 @@ func taxonomyRenderer(s *Site, taxes <-chan taxRenderInfo, results chan<- error,
if !viper.GetBool("DisableRSS") { if !viper.GetBool("DisableRSS") {
// XML Feed // XML Feed
s.setUrls(n, base+".xml") n.Url = s.permalinkStr(base + "/index.xml")
n.Permalink = s.permalink(base)
rssLayouts := []string{"taxonomy/" + t.singular + ".rss.xml", "_default/rss.xml", "rss.xml", "_internal/_default/rss.xml"} rssLayouts := []string{"taxonomy/" + t.singular + ".rss.xml", "_default/rss.xml", "rss.xml", "_internal/_default/rss.xml"}
b, err := s.renderXML("taxonomy "+t.singular+" rss", n, s.appendThemeTemplates(rssLayouts)...) b, err := s.renderXML("taxonomy "+t.singular+" rss", n, s.appendThemeTemplates(rssLayouts)...)
if err != nil { if err != nil {
results <- err results <- err
continue continue
} else { } else {
err := s.WriteDestFile(base+".xml", b) err := s.WriteDestFile(base+"/index.xml", b)
if err != nil { if err != nil {
results <- err results <- err
} }
@ -935,16 +936,16 @@ func (s *Site) RenderSectionLists() error {
return err return err
} }
if !viper.GetBool("DisableRSS") { if !viper.GetBool("DisableRSS") && section != "" {
// XML Feed // XML Feed
fmt.Println("Section...") n.Url = s.permalinkStr(section + "/index.xml")
n.Permalink = s.permalink(section)
rssLayouts := []string{"section/" + section + ".rss.xml", "_default/rss.xml", "rss.xml", "_internal/_default/rss.xml"} rssLayouts := []string{"section/" + section + ".rss.xml", "_default/rss.xml", "rss.xml", "_internal/_default/rss.xml"}
s.setUrls(n, section+".xml")
b, err = s.renderXML("section "+section+" rss", n, s.appendThemeTemplates(rssLayouts)...) b, err = s.renderXML("section "+section+" rss", n, s.appendThemeTemplates(rssLayouts)...)
if err != nil { if err != nil {
return err return err
} }
if err := s.WriteDestFile(section+".xml", b); err != nil { if err := s.WriteDestFile(section+"/index.xml", b); err != nil {
return err return err
} }
} }
@ -973,9 +974,8 @@ func (s *Site) RenderHomePage() error {
if !viper.GetBool("DisableRSS") { if !viper.GetBool("DisableRSS") {
// XML Feed // XML Feed
n.Url = helpers.Urlize("index.xml") n.Url = s.permalinkStr("index.xml")
n.Title = "Recent Content" n.Title = ""
n.Permalink = s.permalink("index.xml")
high := 50 high := 50
if len(s.Pages) < high { if len(s.Pages) < high {
high = len(s.Pages) high = len(s.Pages)
@ -985,15 +985,13 @@ func (s *Site) RenderHomePage() error {
n.Date = s.Pages[0].Date n.Date = s.Pages[0].Date
} }
if !viper.GetBool("DisableRSS") { rssLayouts := []string{"rss.xml", "_default/rss.xml", "_internal/_default/rss.xml"}
rssLayouts := []string{"rss.xml", "_default/rss.xml", "_internal/_default/rss.xml"} b, err := s.renderXML("homepage rss", n, s.appendThemeTemplates(rssLayouts)...)
b, err := s.renderXML("homepage rss", n, s.appendThemeTemplates(rssLayouts)...) if err != nil {
if err != nil { return err
return err }
} if err := s.WriteDestFile("index.xml", b); err != nil {
if err := s.WriteDestFile("rss.xml", b); err != nil { return err
return err
}
} }
} }

View file

@ -45,13 +45,15 @@ func (t *GoHtmlTemplate) EmbedTemplates() {
t.AddInternalTemplate("_default", "rss.xml", `<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> t.AddInternalTemplate("_default", "rss.xml", `<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel> <channel>
<title>{{ .Title }} on {{ .Site.Title }} </title> <title>{{ with .Title }}{{.}} on {{ end }}{{ .Site.Title }}</title>
<generator uri="https://gohugo.io">Hugo</generator>
<link>{{ .Permalink }}</link> <link>{{ .Permalink }}</link>
<description>Recent content {{ with .Title }}in {{.}} {{ end }}on {{ .Site.Title }}</description>
<generator>Hugo -- gohugo.io</generator>
{{ with .Site.LanguageCode }}<language>{{.}}</language>{{end}} {{ with .Site.LanguageCode }}<language>{{.}}</language>{{end}}
{{ with .Site.Author.name }}<author>{{.}}</author>{{end}} {{ with .Site.Author.name }}<author>{{.}}</author>{{end}}
{{ with .Site.Copyright }}<copyright>{{.}}</copyright>{{end}} {{ with .Site.Copyright }}<copyright>{{.}}</copyright>{{end}}
<updated>{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 MST" }}</updated> <lastBuildDate>{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 MST" }}</lastBuildDate>
<atom:link href="{{.Url}}" rel="self" type="application/rss+xml" />
{{ range first 15 .Data.Pages }} {{ range first 15 .Data.Pages }}
<item> <item>
<title>{{ .Title }}</title> <title>{{ .Title }}</title>