Sitemap
頁面物件上的 Sitemap
方法僅能在 Sitemap 模板 中使用。
方法
- changefreq
- (
string
) 頁面可能變動的頻率。有效值為always
、hourly
、daily
、weekly
、monthly
、yearly
,和never
。當為預設值""
時,Hugo 將從 Sitemap 中省略此欄位。詳見 網站地圖詳細說明。
{{ .Sitemap.ChangeFreq }}
- disable New in v0.125.0
- (
bool
) 是否禁用頁面的包含。預設為false
,若在 front matter 中設為true
,將排除該頁面。
{{ .Sitemap.Disable }}
- priority
- (
float
) 頁面相對於網站上其他頁面的優先級。有效值範圍從 0.0 到 1.0。當為預設值-1
時,Hugo 將省略此欄位。詳見 網站地圖詳細說明。
{{ .Sitemap.Priority }}
範例
這是該站點的配置:
hugo.
sitemap:
changeFreq: monthly
[sitemap]
changeFreq = 'monthly'
{
"sitemap": {
"changeFreq": "monthly"
}
}
以及這些內容:
content/news.md
---
sitemap:
changeFreq: hourly
title: News
---
+++
title = 'News'
[sitemap]
changeFreq = 'hourly'
+++
{
"sitemap": {
"changeFreq": "hourly"
},
"title": "News"
}
這是簡單的 sitemap 模板:
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>
在這個範例中,News
頁面的更動頻率為 hourly
,而其他頁面的為 monthly
。