9abd3043a Add docs for shimming JS libraries 6a1c8dcd7 Update sitemap-template.md (#1245) 37c397332 Update frontends.md a0f86f6df Update configuration.md bb00cb2c1 Update page-bundles.md 773212de6 Restructure and simplify fcba7dddf Some minor clarifications of weight sorting 759b967fc Update configuration-markup.md 56708f0b7 module import path remove slash at end 59f4f4acd Doc: Fix typo in hugo command faacf2e97 Clarify pagination documentation (#1208) d8eb60887 netlify: Bump to 0.75.1 8cedf6231 Merge branch 'temp751' 188e2bf56 releaser: Add release notes to /docs for release of 0.75.1 c96d4b7a3 Update index.md 1a9d192f7 Update index.md 32731b916 Update index.md a5bfa0c9a Restore the ... home page b6850bf96 Release 0.75.0 d6e5e624f releaser: Add release notes to /docs for release of 0.75.0 8cd6b4f47 typo: already -> already 2cb2b22bb Merge commit '534ae9c57a902aea9ed6e62390dec11fa74b7122' e3525de23 docs: Regen docs helper fd746dd83 docs: Regenerate CLI docs e20127980 Add "hugo mod npm pack" 8e82c7ce1 markup/highlight: Add support to linkable line anchors on Chroma 21e94911b markup/asciidocext: Fix AsciiDoc TOC with code 50b8dace5 modules: Add noVendor to module config d05b541fe modules: Make ignoreVendor a glob pattern c946082e7 docs: Update replaceRE func 149054341 docs: Update replace func d917567df docs: Update merge function f1e093c92 docs: Regen CLI docs c7bac967d docs: Regen docs helper 7a38f7a45 Merge commit '7d7771b673e5949f554515a2c236b23192c765c8' 1a5a7263a markup/asciidoc: Add support for .TableOfContents git-subtree-dir: docs git-subtree-split: 9abd3043a9214b390e8cc148f4588bf630620851
3.4 KiB
title | description | date | publishdate | lastmod | categories | keywords | menu | weight | sections_weight | draft | aliases | toc | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Sitemap Template | Hugo ships with a built-in template file observing the v0.9 of the Sitemap Protocol, but you can override this template if needed. | 2017-02-01 | 2017-02-01 | 2017-02-01 |
|
|
|
160 | 160 | false |
|
false |
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
.
A sitemap is a Page
and therefore has all the page variables available to use in this template along with Sitemap-specific ones:
.Sitemap.ChangeFreq
- The page change frequency
.Sitemap.Priority
- The priority of the page
.Sitemap.Filename
- The sitemap filename
If provided, Hugo will use /layouts/sitemap.xml
instead of the internal sitemap.xml
template that ships with Hugo.
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 1.0 of the Sitemap Protocol.
{{ printf "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\" ?>" | safeHTML }}
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xhtml="http://www.w3.org/1999/xhtml">
{{ range .Data.Pages }}
<url>
<loc>{{ .Permalink }}</loc>{{ if not .Lastmod.IsZero }}
<lastmod>{{ safeHTML ( .Lastmod.Format "2006-01-02T15:04:05-07:00" ) }}</lastmod>{{ end }}{{ with .Sitemap.ChangeFreq }}
<changefreq>{{ . }}</changefreq>{{ end }}{{ if ge .Sitemap.Priority 0.0 }}
<priority>{{ .Sitemap.Priority }}</priority>{{ end }}{{ if .IsTranslated }}{{ range .Translations }}
<xhtml:link
rel="alternate"
hreflang="{{ .Lang }}"
href="{{ .Permalink }}"
/>{{ end }}
<xhtml:link
rel="alternate"
hreflang="{{ .Lang }}"
href="{{ .Permalink }}"
/>{{ end }}
</url>
{{ end }}
</urlset>
Hugo's sitemapindex.xml
This is used to create a Sitemap index in multilingual mode:
{{ printf "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\" ?>" | safeHTML }}
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
{{ range . }}
<sitemap>
<loc>{{ .SitemapAbsURL }}</loc>
{{ if not .LastChange.IsZero }}
<lastmod>{{ .LastChange.Format "2006-01-02T15:04:05-07:00" | safeHTML }}</lastmod>
{{ end }}
</sitemap>
{{ end }}
</sitemapindex>
Configure sitemap.xml
Defaults for <changefreq>
, <priority>
and filename
values can be set in the site's config file, e.g.:
{{< code-toggle file="config" >}} [sitemap] changefreq = "monthly" priority = 0.5 filename = "sitemap.xml" {{</ code-toggle >}}
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.