Allow renaming of sitemap.xml

This commit is contained in:
Gerben Castel 2015-12-10 19:39:06 +00:00 committed by Steve Francia
parent 26d23f7f4b
commit 6cdb8109cf
4 changed files with 14 additions and 5 deletions

View file

@ -222,7 +222,7 @@ func LoadDefaultSettings() {
viper.SetDefault("RemovePathAccents", false) viper.SetDefault("RemovePathAccents", false)
viper.SetDefault("Taxonomies", map[string]string{"tag": "tags", "category": "categories"}) viper.SetDefault("Taxonomies", map[string]string{"tag": "tags", "category": "categories"})
viper.SetDefault("Permalinks", make(hugolib.PermalinkOverrides, 0)) viper.SetDefault("Permalinks", make(hugolib.PermalinkOverrides, 0))
viper.SetDefault("Sitemap", hugolib.Sitemap{Priority: -1}) viper.SetDefault("Sitemap", hugolib.Sitemap{Priority: -1, Filename: "sitemap.xml"})
viper.SetDefault("DefaultExtension", "html") viper.SetDefault("DefaultExtension", "html")
viper.SetDefault("PygmentsStyle", "monokai") viper.SetDefault("PygmentsStyle", "monokai")
viper.SetDefault("PygmentsUseClasses", false) viper.SetDefault("PygmentsUseClasses", false)

View file

@ -23,6 +23,7 @@ along with Sitemap-specific ones:
**.Sitemap.ChangeFreq** The page change frequency<br> **.Sitemap.ChangeFreq** The page change frequency<br>
**.Sitemap.Priority** The priority of the page<br> **.Sitemap.Priority** The priority of the page<br>
**.Sitemap.Filename** The sitemap filename<br>
In addition to the standard node variables, the homepage has access to all In addition to the standard node variables, the homepage has access to all
site pages through `.Data.Pages`. site pages through `.Data.Pages`.
@ -53,10 +54,11 @@ on render. Please don't include this in the template as it's not valid HTML.*
## Configuring sitemap.xml ## Configuring sitemap.xml
Defaults for `<changefreq>` and `<priority>` values can be set in the site's config file, e.g.: Defaults for `<changefreq>`, `<priority>` and `filename` values can be set in the site's config file, e.g.:
[sitemap] [sitemap]
changefreq = "monthly" changefreq = "monthly"
priority = 0.5 priority = 0.5
filename = "sitemap.xml"
The same fields can be specified in an individual page's front matter in order to override the value for that page. The same fields can be specified in an individual page's front matter in order to override the value for that page.

View file

@ -1541,11 +1541,15 @@ func (s *Site) RenderSitemap() error {
if page.Sitemap.Priority == -1 { if page.Sitemap.Priority == -1 {
page.Sitemap.Priority = sitemapDefault.Priority page.Sitemap.Priority = sitemapDefault.Priority
} }
if page.Sitemap.Filename == "" {
page.Sitemap.Filename = sitemapDefault.Filename
}
} }
smLayouts := []string{"sitemap.xml", "_default/sitemap.xml", "_internal/_default/sitemap.xml"} smLayouts := []string{"sitemap.xml", "_default/sitemap.xml", "_internal/_default/sitemap.xml"}
if err := s.renderAndWriteXML("sitemap", "sitemap.xml", n, s.appendThemeTemplates(smLayouts)...); err != nil { if err := s.renderAndWriteXML("sitemap", page.Sitemap.Filename, n, s.appendThemeTemplates(smLayouts)...); err != nil {
return err return err
} }

View file

@ -21,10 +21,11 @@ import (
type Sitemap struct { type Sitemap struct {
ChangeFreq string ChangeFreq string
Priority float64 Priority float64
Filename string
} }
func parseSitemap(input map[string]interface{}) Sitemap { func parseSitemap(input map[string]interface{}) Sitemap {
sitemap := Sitemap{Priority: -1} sitemap := Sitemap{Priority: -1, Filename: "sitemap.xml"}
for key, value := range input { for key, value := range input {
switch key { switch key {
@ -32,6 +33,8 @@ func parseSitemap(input map[string]interface{}) Sitemap {
sitemap.ChangeFreq = cast.ToString(value) sitemap.ChangeFreq = cast.ToString(value)
case "priority": case "priority":
sitemap.Priority = cast.ToFloat64(value) sitemap.Priority = cast.ToFloat64(value)
case "filename":
sitemap.Filename = cast.ToString(value)
default: default:
jww.WARN.Printf("Unknown Sitemap field: %s\n", key) jww.WARN.Printf("Unknown Sitemap field: %s\n", key)
} }