| 1 |
--- |
| 2 |
title: Sitemap |
| 3 |
description: Returns the sitemap settings for the given page as defined in front matter, falling back to the sitemap settings as defined in your project configuration. |
| 4 |
categories: [] |
| 5 |
keywords: [] |
| 6 |
params: |
| 7 |
functions_and_methods: |
| 8 |
returnType: config.SitemapConfig |
| 9 |
signatures: [PAGE.Sitemap] |
| 10 |
--- |
| 11 |
|
| 12 |
Access to the `Sitemap` method on a `Page` object is restricted to [sitemap templates][]. |
| 13 |
|
| 14 |
## Methods |
| 15 |
|
| 16 |
Use these methods on the `Sitemap` object. |
| 17 |
|
| 18 |
`ChangeFreq` |
| 19 |
: (`string`) How frequently a page is likely to change. Valid values are `always`, `hourly`, `daily`, `weekly`, `monthly`, `yearly`, and `never`. With the default value of `""` Hugo will omit this field from the sitemap. See [details][changefreqdef]. |
| 20 |
|
| 21 |
```go-html-template |
| 22 |
{{ .Sitemap.ChangeFreq }} |
| 23 |
``` |
| 24 |
|
| 25 |
`Disable` |
| 26 |
: (`bool`) Whether to disable page inclusion. Default is `false`. Set to `true` in front matter to exclude the page. |
| 27 |
|
| 28 |
```go-html-template |
| 29 |
{{ .Sitemap.Disable }} |
| 30 |
``` |
| 31 |
|
| 32 |
`Priority` |
| 33 |
: (`float`) The priority of a page relative to any other page on the site. Valid values range from 0.0 to 1.0. With the default value of `-1` Hugo will omit this field from the sitemap. See [details][prioritydef]. |
| 34 |
|
| 35 |
```go-html-template |
| 36 |
{{ .Sitemap.Priority }} |
| 37 |
``` |
| 38 |
|
| 39 |
## Example |
| 40 |
|
| 41 |
With this project configuration: |
| 42 |
|
| 43 |
{{< code-toggle file=hugo >}} |
| 44 |
[sitemap] |
| 45 |
changeFreq = 'monthly' |
| 46 |
{{< /code-toggle >}} |
| 47 |
|
| 48 |
And this content: |
| 49 |
|
| 50 |
{{< code-toggle file=content/news.md fm=true >}} |
| 51 |
title = 'News' |
| 52 |
[sitemap] |
| 53 |
changeFreq = 'hourly' |
| 54 |
{{< /code-toggle >}} |
| 55 |
|
| 56 |
And this simplistic sitemap template: |
| 57 |
|
| 58 |
```xml {file="layouts/sitemap.xml"} |
| 59 |
{{ printf "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>" | safeHTML }} |
| 60 |
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" |
| 61 |
xmlns:xhtml="http://www.w3.org/1999/xhtml"> |
| 62 |
{{ range .Pages }} |
| 63 |
<url> |
| 64 |
<loc>{{ .Permalink }}</loc> |
| 65 |
{{ if not .Lastmod.IsZero }} |
| 66 |
<lastmod>{{ .Lastmod.Format "2006-01-02T15:04:05-07:00" | safeHTML }}</lastmod> |
| 67 |
{{ end }} |
| 68 |
{{ with .Sitemap.ChangeFreq }} |
| 69 |
<changefreq>{{ . }}</changefreq> |
| 70 |
{{ end }} |
| 71 |
</url> |
| 72 |
{{ end }} |
| 73 |
</urlset> |
| 74 |
``` |
| 75 |
|
| 76 |
The change frequency will be `hourly` for the news page, and `monthly` for other pages. |
| 77 |
|
| 78 |
[changefreqdef]: https://www.sitemaps.org/protocol.html#changefreqdef |
| 79 |
[prioritydef]: https://www.sitemaps.org/protocol.html#prioritydef |
| 80 |
[sitemap templates]: /templates/sitemap/ |