github.com/lyeb/hugo@v0.47.1/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  ## Sitemap Templates
    39  
    40  Hugo has built-on Sitemap templates, but you can provide your own if needed, in either `layouts/sitemap.xml` or `layouts/_default/sitemap.xml`.
    41  
    42  For multilingual sites, we also create a Sitemap index. You can provide a custom layout for that in either `layouts/sitemapindex.xml` or `layouts/_default/sitemapindex.xml`.
    43  
    44  ## Hugo’s sitemap.xml
    45  
    46  This template respects the version 0.9 of the [Sitemap Protocol](http://www.sitemaps.org/protocol.html).
    47  
    48  ```xml
    49  <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
    50    xmlns:xhtml="http://www.w3.org/1999/xhtml">
    51    {{ range .Data.Pages }}
    52    <url>
    53      <loc>{{ .Permalink }}</loc>{{ if not .Lastmod.IsZero }}
    54      <lastmod>{{ safeHTML ( .Lastmod.Format "2006-01-02T15:04:05-07:00" ) }}</lastmod>{{ end }}{{ with .Sitemap.ChangeFreq }}
    55      <changefreq>{{ . }}</changefreq>{{ end }}{{ if ge .Sitemap.Priority 0.0 }}
    56      <priority>{{ .Sitemap.Priority }}</priority>{{ end }}{{ if .IsTranslated }}{{ range .Translations }}
    57      <xhtml:link
    58                  rel="alternate"
    59                  hreflang="{{ .Lang }}"
    60                  href="{{ .Permalink }}"
    61                  />{{ end }}
    62      <xhtml:link
    63                  rel="alternate"
    64                  hreflang="{{ .Lang }}"
    65                  href="{{ .Permalink }}"
    66                  />{{ end }}
    67    </url>
    68    {{ end }}
    69  </urlset>
    70  ```
    71  
    72  {{% note %}}
    73  Hugo will automatically add the following header line to this file
    74  on render. Please don't include this in the template as it's not valid HTML.
    75  
    76  `<?xml version="1.0" encoding="utf-8" standalone="yes" ?>`
    77  {{% /note %}}
    78  
    79  ## Hugo's sitemapindex.xml
    80  
    81  This is used to create a Sitemap index in multilingual mode:
    82  
    83  ```xml
    84  <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
    85  	{{ range . }}
    86  	<sitemap>
    87  	   	<loc>{{ .SitemapAbsURL }}</loc>
    88  		{{ if not .LastChange.IsZero }}
    89  	   	<lastmod>{{ .LastChange.Format "2006-01-02T15:04:05-07:00" | safeHTML }}</lastmod>
    90  		{{ end }}
    91  	</sitemap>
    92  	{{ end }}
    93  </sitemapindex>
    94  ```
    95  
    96  ## Configure `sitemap.xml`
    97  
    98  Defaults for `<changefreq>`, `<priority>` and `filename` values can be set in the site's config file, e.g.:
    99  
   100  {{< code-toggle file="config" >}}
   101  [sitemap]
   102    changefreq = "monthly"
   103    priority = 0.5
   104    filename = "sitemap.xml"
   105  {{</ code-toggle >}}
   106  
   107  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.
   108  
   109  
   110  
   111  [pagevars]: /variables/page/