hugo/docs/content/en/methods/page/Sitemap.md
Bjørn Erik Pedersen 5fd1e74903
Merge commit '9b0050e9aabe4be65c78ccf292a348f309d50ccd' as 'docs'
```
git subtree add --prefix=docs/ https://github.com/gohugoio/hugoDocs.git master --squash
```

Closes #11925
2024-01-27 10:48:57 +01:00

1.9 KiB

title description categories keywords action toc
Sitemap Returns the sitemap settings for the given page as defined in front matter, falling back to the sitemap settings as defined in the site configuration.
related returnType signatures
config.SitemapConfig
PAGE.Sitemap
true

Access to the Sitemap method on a Page object is restricted to sitemap templates.

Methods

ChangeFreq
(string) How frequently a page is likely to change. Valid values are always, hourly, daily, weekly, monthly, yearly, and never. Default is "" (change frequency omitted from rendered sitemap).
{{ .Sitemap.ChangeFreq }}
Priority
(float) 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 (priority omitted from rendered sitemap).
{{ .Sitemap.Priority }}

Example

With this site configuration:

{{< code-toggle file=hugo >}} [sitemap] changeFreq = 'monthly' {{< /code-toggle >}}

And this content:

{{< code-toggle file=content/news.md fm=true >}} title = 'News' [sitemap] changeFreq = 'hourly' {{< /code-toggle >}}

And this simplistic sitemap template:

{{< code file=layouts/_default/sitemap.xml >}} {{ printf "" | safeHTML }} {{ range .Pages }} {{ .Permalink }} {{ if not .Lastmod.IsZero }} {{ .Lastmod.Format "2006-01-02T15:04:05-07:00" | safeHTML }} {{ end }} {{ with .Sitemap.ChangeFreq }} {{ . }} {{ end }} {{ end }} {{< /code >}}

The change frequency will be hourly for the news page, and monthly for other pages.