站点地图
Syntax
PAGE.Sitemap
Returns
config.SitemapConfig
Page 对象上的 Sitemap 方法的访问权限仅限于 站点地图模板 。
方法
- changefreq
- (
string) 页面变化的频率。有效值为always、hourly、daily、weekly、monthly、yearly和never。使用默认值""时,Hugo 将忽略站点地图中的此字段。参见 详情 。
{{ .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"
}
以及这个简单的站点地图模板:
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>新闻页面的更改频率将为 hourly ,其他页面的更改频率将为 monthly 。