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 字段是追加到而不是替換站點配置的輸出。