站点地图
语法
PAGE.Sitemap
返回
config.SitemapConfig
对 Page
对象上的 Sitemap
方法的访问仅限于 站点地图模板。
方法
- changefreq
- (
string
)页面可能更改的频率。有效值为always
、hourly
、daily
、weekly
、monthly
、yearly
和never
。默认值为""
,Hugo 将从站点地图中省略此字段。请参阅 详细信息。
{{ .Sitemap.ChangeFreq }}
- disable v0.125.0 新增功能
- (
bool
)是否禁用页面包含。默认值为false
。在前言中设置为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
。