配置内容类型
配置内容类型。
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": {}
}
}