github.com/shohhei1126/hugo@v0.42.2-0.20180623210752-3d5928889ad7/docs/content/en/templates/sitemap-template.md (about)

     1  ---
     2  title: Sitemap Template
     3  # linktitle: Sitemap
     4  description: Hugo ships with a built-in template file observing the v0.9 of the Sitemap Protocol, but you can override this template if needed.
     5  date: 2017-02-01
     6  publishdate: 2017-02-01
     7  lastmod: 2017-02-01
     8  categories: [templates]
     9  keywords: [sitemap, xml, templates]
    10  menu:
    11    docs:
    12      parent: "templates"
    13      weight: 160
    14  weight: 160
    15  sections_weight: 160
    16  draft: false
    17  aliases: [/layout/sitemap/,/templates/sitemap/]
    18  toc: false
    19  ---
    20  
    21  A single Sitemap template is used to generate the `sitemap.xml` file.
    22  Hugo automatically comes with this template file. *No work is needed on
    23  the users' part unless they want to customize `sitemap.xml`.*
    24  
    25  A sitemap is a `Page` and therefore has all the [page variables][pagevars] available to use in this template along with Sitemap-specific ones:
    26  
    27  `.Sitemap.ChangeFreq`
    28  : The page change frequency
    29  
    30  `.Sitemap.Priority`
    31  : The priority of the page
    32  
    33  `.Sitemap.Filename`
    34  : The sitemap filename
    35  
    36  If provided, Hugo will use `/layouts/sitemap.xml` instead of the internal `sitemap.xml` template that ships with Hugo.
    37  
    38  ## Hugo’s sitemap.xml
    39  
    40  This template respects the version 0.9 of the [Sitemap Protocol](http://www.sitemaps.org/protocol.html).
    41  
    42  ```
    43  <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
    44    {{ range .Data.Pages }}
    45    <url>
    46      <loc>{{ .Permalink }}</loc>{{ if not .Lastmod.IsZero }}
    47      <lastmod>{{ safeHTML ( .Lastmod.Format "2006-01-02T15:04:05-07:00" ) }}</lastmod>{{ end }}{{ with .Sitemap.ChangeFreq }}
    48      <changefreq>{{ . }}</changefreq>{{ end }}{{ if ge .Sitemap.Priority 0.0 }}
    49      <priority>{{ .Sitemap.Priority }}</priority>{{ end }}
    50    </url>
    51    {{ end }}
    52  </urlset>
    53  ```
    54  
    55  {{% note %}}
    56  Hugo will automatically add the following header line to this file
    57  on render. Please don't include this in the template as it's not valid HTML.
    58  
    59  `<?xml version="1.0" encoding="utf-8" standalone="yes" ?>`
    60  {{% /note %}}
    61  
    62  ## Configure `sitemap.xml`
    63  
    64  Defaults for `<changefreq>`, `<priority>` and `filename` values can be set in the site's config file, e.g.:
    65  
    66  {{< code-toggle file="config" >}}
    67  [sitemap]
    68    changefreq = "monthly"
    69    priority = 0.5
    70    filename = "sitemap.xml"
    71  {{</ code-toggle >}}
    72  
    73  The same fields can be specified in an individual content file's front matter in order to override the value assigned to that piece of content at render time.
    74  
    75  [pagevars]: /variables/page/