站点地图模板
概述
Hugo 的嵌入式站点地图模板符合 站点地图协议 的 v0.9 版本。
对于单语言项目,Hugo 使用 嵌入式站点地图模板 在 publishDir
的根目录下生成一个 sitemap.xml 文件。
对于多语言项目,Hugo 会生成:
- 使用 嵌入式站点地图模板 在每个站点(语言)的根目录下生成一个 sitemap.xml 文件。
- 使用 嵌入式站点地图索引模板 在
publishDir
的根目录下生成一个 sitemap.xml 文件。
配置
这些是站点地图的默认配置值。除非在 front matter 中被覆盖,否则它们适用于所有页面。
hugo.
sitemap:
changeFreq: ""
disable: false
filename: sitemap.xml
priority: -1
[sitemap]
changeFreq = ''
disable = false
filename = 'sitemap.xml'
priority = -1
{
"sitemap": {
"changeFreq": "",
"disable": false,
"filename": "sitemap.xml",
"priority": -1
}
}
- changefreq
- (
string
) 页面更改的频率。有效值为always
、hourly
、daily
、weekly
、monthly
、yearly
和never
。使用默认值""
时,Hugo 将省略站点地图中的此字段。参见 详情 。 - disable New in v0.125.0
- (
bool
) 是否禁用页面包含。默认为false
。在 front matter 中设置为true
以排除页面。 - filename
- (
string
) 生成的文件名。默认为sitemap.xml
。 - priority
- (
float
) 页面相对于站点上任何其他页面的优先级。有效值范围为 0.0 到 1.0。使用默认值-1
时,Hugo 将省略站点地图中的此字段。参见 详情 。
覆盖默认值
在 front matter 中覆盖给定页面的默认值。
news.md
---
sitemap:
changefreq: weekly
disable: true
priority: 0.8
title: News
---
+++
title = 'News'
[sitemap]
changefreq = 'weekly'
disable = true
priority = 0.8
+++
{
"sitemap": {
"changefreq": "weekly",
"disable": true,
"priority": 0.8
},
"title": "News"
}
覆盖内置模板
要覆盖内置的 sitemap.xml 模板,请在以下任一位置创建一个新文件:
- layouts/sitemap.xml
- layouts/_default/sitemap.xml
在遍历页面集合时,分别使用 .Sitemap.ChangeFreq
和 .Sitemap.Priority
访问 更改频率 和 优先级 。
要覆盖内置的 sitemapindex.xml 模板,请在以下任一位置创建一个新文件:
- layouts/sitemapindex.xml
- layouts/_default/sitemapindex.xml
禁用站点地图生成
您可以在站点配置中禁用站点地图生成:
hugo.
disableKinds:
- sitemap
disableKinds = ['sitemap']
{
"disableKinds": [
"sitemap"
]
}