Allow renaming of sitemap.xml
authorGerben Castel <gerben.castel@gmail.com>
Thu, 10 Dec 2015 19:39:06 +0000 (19:39 +0000)
committerSteve Francia <steve.francia@gmail.com>
Mon, 4 Jan 2016 17:28:49 +0000 (12:28 -0500)
commands/hugo.go
docs/content/templates/sitemap.md
hugolib/site.go
hugolib/sitemap.go

index 66edcfce1cc4f24676c7aefa8fa82f5427deb176..4d3f9bab6a59bc220333260317f0dcda008c6fae 100644 (file)
@@ -222,7 +222,7 @@ func LoadDefaultSettings() {
        viper.SetDefault("RemovePathAccents", false)
        viper.SetDefault("Taxonomies", map[string]string{"tag": "tags", "category": "categories"})
        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("PygmentsStyle", "monokai")
        viper.SetDefault("PygmentsUseClasses", false)
index 39d9b803ed702e9a5785b96294bf9d8ad558ef53..701f06363cd7454afa80d59e05b1114df5d37cc6 100644 (file)
@@ -23,6 +23,7 @@ along with Sitemap-specific ones:
 
 **.Sitemap.ChangeFreq** The page change frequency<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
 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
 
-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]
       changefreq = "monthly"
       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.
\ No newline at end of file
+The same fields can be specified in an individual page's front matter in order to override the value for that page.
index ec0eb886f8ee9c695418567216a341fbb7f99e1c..f93d6ff6b32c227c57a63f3d4b97ff0a54d1d099 100644 (file)
@@ -1541,11 +1541,15 @@ func (s *Site) RenderSitemap() error {
                if page.Sitemap.Priority == -1 {
                        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"}
 
-       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
        }
 
index 3f3a28cd2ed96c34c1cd47f9c683bf1dd6d5c47e..54e1d076e5a5476ae2ed38d1e6b019d28608f699 100644 (file)
@@ -21,10 +21,11 @@ import (
 type Sitemap struct {
        ChangeFreq string
        Priority   float64
+       Filename   string
 }
 
 func parseSitemap(input map[string]interface{}) Sitemap {
-       sitemap := Sitemap{Priority: -1}
+       sitemap := Sitemap{Priority: -1, Filename: "sitemap.xml"}
 
        for key, value := range input {
                switch key {
@@ -32,6 +33,8 @@ func parseSitemap(input map[string]interface{}) Sitemap {
                        sitemap.ChangeFreq = cast.ToString(value)
                case "priority":
                        sitemap.Priority = cast.ToFloat64(value)
+               case "filename":
+                       sitemap.Filename = cast.ToString(value)
                default:
                        jww.WARN.Printf("Unknown Sitemap field: %s\n", key)
                }