配置內容類型
配置內容類型。
New in
v0.144.0
Hugo 支持六種 內容格式:
| 內容格式 | 媒體類型 | 標識符 | 文件擴展名 |
|---|---|---|---|
| Markdown | text/markdown |
markdown |
markdown,md, mdown |
| HTML | text/html |
html |
htm, html |
| Emacs Org Mode | text/org |
org |
org |
| AsciiDoc | text/asciidoc |
asciidoc |
ad, adoc, asciidoc |
| Pandoc | text/pandoc |
pandoc |
pandoc, pdc |
| reStructuredText | text/rst |
rst |
rst |
這些可以用作頁面內容或 頁面資源。當用作頁面資源時,其 資源類型 為 page。
考慮這個 頁面捆綁 示例:
content/
└── example/
├── index.md <-- 內容
├── a.adoc <-- 資源(資源類型:page)
├── b.html <-- 資源(資源類型:page)
├── c.md <-- 資源(資源類型:page)
├── d.org <-- 資源(資源類型:page)
├── e.pdc <-- 資源(資源類型:page)
├── f.rst <-- 資源(資源類型:page)
├── g.jpg <-- 資源(資源類型:image)
└── h.png <-- 資源(資源類型:image)index.md 文件是頁面的內容,而其他文件是頁面資源。文件 a 到 f 的資源類型為 page,而 g 和 h 的資源類型為 image。
當您構建站點時,Hugo 不會發布資源類型為 page 的頁面資源。例如,這是構建上述站點的結果:
public/
├── example/
│ ├── g.jpg
│ ├── h.png
│ └── index.html
└── index.html默認行為在大多數情況下都是合適的。鑑於包含標記的頁面資源通常用於包含在主內容中,單獨發布它們通常是不希望的。
默認行為由 contentTypes 配置確定:
contentTypes:
text/asciidoc: {}
text/html: {}
text/markdown: {}
text/org: {}
text/pandoc: {}
text/rst: {}
[contentTypes]
[contentTypes.'text/asciidoc']
[contentTypes.'text/html']
[contentTypes.'text/markdown']
[contentTypes.'text/org']
[contentTypes.'text/pandoc']
[contentTypes.'text/rst']
{
"contentTypes": {
"text/asciidoc": {},
"text/html": {},
"text/markdown": {},
"text/org": {},
"text/pandoc": {},
"text/rst": {}
}
}
在此默認配置中,具有這些媒體類型的頁面資源的資源類型為 page,並且不會自動發布。要將為給定媒體類型分配的資源類型從 page 更改為 text,請從列表中刪除相應的條目。
例如,要將 text/html 文件的資源類型設置為 text,從而啟用自動發布,請刪除 text/html 條目:
contentTypes:
text/asciidoc: {}
text/markdown: {}
text/org: {}
text/pandoc: {}
text/rst: {}
[contentTypes]
[contentTypes.'text/asciidoc']
[contentTypes.'text/markdown']
[contentTypes.'text/org']
[contentTypes.'text/pandoc']
[contentTypes.'text/rst']
{
"contentTypes": {
"text/asciidoc": {},
"text/markdown": {},
"text/org": {},
"text/pandoc": {},
"text/rst": {}
}
}