summaryrefslogtreecommitdiffstats
path: root/docs/content/en/methods/page/Sitemap.md
blob: 08ff3f5d06740e763e664716bf8fc67d53175a02 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
---
title: Sitemap
description: 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.
categories: []
keywords: []
action:
  related: []
  returnType: config.SitemapConfig
  signatures: [PAGE.Sitemap]
toc: 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).

```go-html-template
{{ .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).

```go-html-template
{{ .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 "<?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 .Pages }}
    <url>
      <loc>{{ .Permalink }}</loc>
      {{ if not .Lastmod.IsZero }}
        <lastmod>{{ .Lastmod.Format "2006-01-02T15:04:05-07:00" | safeHTML }}</lastmod>
      {{ end }}
      {{ with .Sitemap.ChangeFreq }}
        <changefreq>{{ . }}</changefreq>
      {{ end }}
    </url>
  {{ end }}
</urlset>
{{< /code >}}

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

[sitemap templates]: /templates/sitemap-template/