Hugo 內容格式
介紹
你可以在整個站點中混合使用內容格式。例如:
content/
└── posts/
├── post-1.md
├── post-2.adoc
├── post-3.org
├── post-4.pandoc
├── post-5.rst
└── post-6.html無論內容格式如何,所有內容都必須有 front matter,最好包括 title 和 date。
Hugo 根據 front matter 中的 markup 標識符選擇內容渲染器,回退到文件擴展名。參見下面的 [分類] 表,了解 markup 標識符和已識別文件擴展名的列表。
格式
Markdown
使用 Markdown 創建內容,前面加上 front matter。
Markdown 是 Hugo 的默認內容格式。Hugo 使用 Goldmark 原生將 Markdown 渲染為 HTML。Goldmark 速度快並且符合 CommonMark 和 GitHub Flavored Markdown 規范。你可以在 站點配置 中配置 Goldmark。
Hugo 提供自定義 Markdown 功能,包括:
- Attributes
- 將 HTML 屬性(如
class和id)應用於 Markdown 圖像和塊元素,包括引用塊、圍欄代碼塊、標題、水平線、列表、段落和表格。 - Extensions
- 利用嵌入式 Markdown 擴展創建表格、定義列表、腳注、任務列表、插入文本、標記文本、下標、上標等。
- Mathematics
- 使用 LaTeX markup 在 Markdown 中包含數學方程和表達式。
- Render hooks
- 在渲染圍欄代碼塊、標題、圖像和鏈接時覆蓋 Markdown 到 HTML 的轉換。例如,將每個獨立圖像渲染為 HTML
figure元素。
HTML
使用 HTML 創建內容,前面加上 front matter。內容通常是你放在 HTML 文檔的 body 或 main 元素中的內容。
Emacs Org Mode
使用 Emacs Org Mode 格式創建內容,前面加上 front matter。你可以使用 Org Mode 關鍵字作為 front matter。參見 [詳情]。
AsciiDoc
使用 AsciiDoc 格式創建內容,前面加上 front matter。Hugo 使用 Asciidoctor 可執行文件將 AsciiDoc 內容渲染為 HTML。你必須安裝 Asciidoctor 及其依賴項(Ruby)才能渲染 AsciiDoc 內容格式。
你可以在 站點配置 中配置 AsciiDoc 渲染器。
在默認配置中,Hugo 在調用 Asciidoctor 可執行文件時傳遞以下 CLI 標志:
--no-header-footer傳遞給 Asciidoctor 可執行文件的 CLI 標志取決於配置。你可以在構建站點時檢查這些標志:
hugo --logLevel infoPandoc
使用 Pandoc 格式 1 創建內容,前面加上 front matter。Hugo 使用 Pandoc 可執行文件將 Pandoc 內容渲染為 HTML。你必須安裝 Pandoc 才能渲染 Pandoc 內容格式。
Hugo 在調用 Pandoc 可執行文件時傳遞以下 CLI 標志:
--mathjaxreStructuredText
使用 reStructuredText 格式創建內容,前面加上 front matter。Hugo 使用 Docutils(特別是 rst2html)將 reStructuredText 內容渲染為 HTML。你必須安裝 Docutils 及其依賴項(Python)才能渲染 reStructuredText 內容格式。
Hugo 在調用 rst2html 可執行文件時傳遞以下 CLI 標志:
--leave-comments --initial-header-level=2分類
| 內容格式 | 媒體類型 | 標識符 | 文件擴展名 |
|---|---|---|---|
| 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 |
將內容轉換為 HTML 時,Hugo 使用:
- Markdown、HTML 和 Emacs Org mode 的原生渲染器
- AsciiDoc、Pandoc 和 reStructuredText 的外部渲染器
原生渲染器比外部渲染器更快。
-
這是 CommonMark 規范描述的 Markdown 格式的派生。 ↩︎