Hugo 配置输出
Hugo 配置为每种页面类型渲染哪些输出格式。
output format(输出格式)是一组设置,定义 Hugo 在构建网站时如何渲染文件。例如,html、json ?rss 是内置输出格式。您可以创建多个输出格式,并根据 page kind(页面类型)控制它们的生成,或通过为特定页面启用一个或多个输出格式
在 配置输出格式 部分了解有关创建和配置输出格式的更多信息。
每种页面类型的输出
以下默认配置确定每种页面类型生成的输出格式:
outputs:
home:
- html
- rss
page:
- html
rss:
- rss
section:
- html
- rss
taxonomy:
- html
- rss
term:
- html
- rss
[outputs]
home = ['html', 'rss']
page = ['html']
rss = ['rss']
section = ['html', 'rss']
taxonomy = ['html', 'rss']
term = ['html', 'rss']
{
"outputs": {
"home": [
"html",
"rss"
],
"page": [
"html"
],
"rss": [
"rss"
],
"section": [
"html",
"rss"
],
"taxonomy": [
"html",
"rss"
],
"term": [
"html",
"rss"
]
}
}
要为 home 页面类型渲染内置的 json 输出格式,假设您已经创建了必要的模板,请将以下内容添加到您的配置中:
outputs:
home:
- html
- rss
- json
[outputs]
home = ['html', 'rss', 'json']
{
"outputs": {
"home": [
"html",
"rss",
"json"
]
}
}
请注意,在此示例中,我们只指定了 home 页面类型。除非您打算修改其他页面类型的默认输出格式,否则不需要为它们包含条目。
上述数组中输出格式的顺序很重要。第一个元素将是该页面类型的 主输出格式,在大多数情况下,如默认配置所示,应该是 html。
给定页面类型的主输出格式确定 Page 对象上的 Permalink 和 RelPermalink 方法返回的值。
详见 链接到输出格式 部分获取详情。
每个页面的输出
使用 front matter 中的 outputs 字段将输出格式添加到页面的渲染中。例如,要在为特定页面渲染的输出格式中包含 json:
---
outputs:
- json
title: Example
---+++
outputs = ['json']
title = 'Example'
+++{
"outputs": [
"json"
],
"title": "Example"
}
在默认配置中,Hugo 将为此页面渲染 html 和 json 输出格式。outputs 字段是追加到而不是替换站点配置的输出。