diff --git a/content/en/templates/sitemap-template.md b/content/en/templates/sitemap-template.md index dee28fc3b..15028f078 100644 --- a/content/en/templates/sitemap-template.md +++ b/content/en/templates/sitemap-template.md @@ -1,10 +1,7 @@ --- -title: Sitemap Template -# linktitle: Sitemap -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. +title: Sitemap Templates +description: Hugo provides built-in sitemap templates. date: 2017-02-01 -publishdate: 2017-02-01 -lastmod: 2017-02-01 categories: [templates] keywords: [sitemap, xml, templates] menu: @@ -15,92 +12,76 @@ weight: 160 sections_weight: 160 draft: false aliases: [/layout/sitemap/,/templates/sitemap/] -toc: false +toc: true --- -A single Sitemap template is used to generate the `sitemap.xml` file. -Hugo automatically comes with this template file. *No work is needed on -the users' part unless they want to customize `sitemap.xml`.* +## Overview -A sitemap is a `Page` and therefore has all the [page variables][pagevars] available to use in this template along with Sitemap-specific ones: +Hugo's built-in sitemap templates conform to v0.9 of the [sitemap protocol]. -`.Sitemap.ChangeFreq` -: The page change frequency +With a monolingual project, Hugo generates a sitemap.xml file in the root of the [`publishDir`] using the internal [sitemap.xml] template. -`.Sitemap.Priority` -: The priority of the page +With a multilingual project, Hugo generates: -`.Sitemap.Filename` -: The sitemap filename +- A sitemap.xml file in the root of each site (language) using the built-in [sitemap.xml] template +- A sitemap.xml file in the root of the [`publishDir`] using the built-in [sitemapindex.xml] template -If provided, Hugo will use `/layouts/sitemap.xml` instead of the internal `sitemap.xml` template that ships with Hugo. +## Configuration -## Sitemap Templates - -Hugo has built-on Sitemap templates, but you can provide your own if needed, in either `layouts/sitemap.xml` or `layouts/_default/sitemap.xml`. - -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`. - -## Hugo’s sitemap.xml - -This template respects the version 0.9 of the [Sitemap Protocol](https://www.sitemaps.org/protocol.html). - -```xml -{{ printf "" | safeHTML }} - - {{ range .Data.Pages }} - - {{ .Permalink }}{{ if not .Lastmod.IsZero }} - {{ safeHTML ( .Lastmod.Format "2006-01-02T15:04:05-07:00" ) }}{{ end }}{{ with .Sitemap.ChangeFreq }} - {{ . }}{{ end }}{{ if ge .Sitemap.Priority 0.0 }} - {{ .Sitemap.Priority }}{{ end }}{{ if .IsTranslated }}{{ range .Translations }} - {{ end }} - {{ end }} - - {{ end }} - -``` - -## Hugo's sitemapindex.xml - -This is used to create a Sitemap index in multilingual mode: - -```xml -{{ printf "" | safeHTML }} - - {{ range . }} - - {{ .SitemapAbsURL }} - {{ if not .LastChange.IsZero }} - {{ .LastChange.Format "2006-01-02T15:04:05-07:00" | safeHTML }} - {{ end }} - - {{ end }} - -``` - -## Configure `sitemap.xml` - -Defaults for ``, `` and `filename` values can be set in the site's config file, e.g.: +Set the default values for [change frequency] and [priority], and the name of the generated file, in your site configuration. {{< code-toggle file="config" >}} [sitemap] - changefreq = "monthly" + changefreq = 'monthly' + filename = 'sitemap.xml' priority = 0.5 - filename = "sitemap.xml" {{}} -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. +changefreq +: How frequently a page is likely to change. Valid values are `always`, `hourly`, `daily`, `weekly`, `monthly`, `yearly`, and `never`. Default is `""` (omitted from rendered sitemap). +filename +: The name of the generated file. Default is `sitemap.xml`. +priority +: The priority of a page relative to any other page on the site. Valid values range from 0.0 to 1.0. Default is `-1` (omitted from rendered sitemap). -[pagevars]: /variables/page/ +## Override Default Values + +Override the default values for a given page in front matter. + +{{< code-toggle file="news.md" fm=true >}} +title = 'News' +[sitemap] + changefreq = 'weekly' + priority = 0.8 +{{}} + +## Override Built-in Templates + +To override the built-in sitemap.xml template, create a new file in either of these locations: + +- layouts/sitemap.xml +- layouts/_default/sitemap.xml + +When ranging through the page collection, access the _change frequency_ and _priority_ with `.Sitemap.ChangeFreq` and `.Sitemap.Priority` respectively. + +To override the built-in sitemapindex.xml template, create a new file in either of these locations: + +- layouts/sitemapindex.xml +- layouts/_default/sitemapindex.xml + +## Disable Sitemap Generation + +You may disable sitemap generation in your site configuration: + +{{< code-toggle file="config" >}} +disableKinds = ['sitemap'] +{{}} + +[`publishDir`]: {{< relref "getting-started/configuration#publishdir" >}} +[change frequency]: +[priority]: +[sitemap protocol]: +[sitemap.xml]: +[sitemapindex.xml]: