CONTENT MANAGEMENT

Content formats

介紹

您可以在整個網站中混合使用內容格式。例如:

content/
└── posts/
    ├── post-1.md
    ├── post-2.adoc
    ├── post-3.org
    ├── post-4.pandoc
    ├── post-5.rst
    └── post-6.html

無論使用何種內容格式,所有內容都必須包含 front matter,最好包括 titledate

Hugo 根據 front matter 中的 markup 標識符選擇內容渲染器,若未設定,則根據文件擴展名選擇。請參閱下方的 分類 表格,了解標識符和識別的文件擴展名。

格式

Markdown

使用 Markdown 格式創建您的內容,並加上 front matter。

Markdown 是 Hugo 預設的內容格式。Hugo 使用 Goldmark 渲染 Markdown 為 HTML。Goldmark 速度快,並符合 CommonMarkGitHub Flavored Markdown 規範。您可以在網站配置中 [配置 Goldmark]。

Hugo 提供自訂的 Markdown 功能,包括:

Attributes
將 HTML 屬性(如 classid)應用於 Markdown 圖片和區塊元素,包括區塊引用、圍欄代碼區塊、標題、水平線、列表、段落和表格。
Extensions
利用內建的 Markdown 擴展來創建表格、定義列表、腳註、任務列表、插入文本、標記文本、下標、上標等。
Mathematics
在 Markdown 中使用 LaTeX 或 TeX 排版語法包含數學方程式和表達式。
Render hooks
在渲染圍欄代碼區塊、標題、圖片和連結時,覆蓋 Markdown 到 HTML 的轉換。例如,將每個獨立的圖片渲染為 HTML figure 元素。

HTML

使用 HTML 格式創建您的內容,並加上 front matter。內容通常放置於 HTML 文檔的 bodymain 元素內。

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 info

Pandoc

使用 Pandoc 格式創建您的內容,並加上 front matter。Hugo 使用 Pandoc 執行檔將 Pandoc 內容渲染為 HTML。您必須安裝 Pandoc 才能使用 Pandoc 內容格式。

Hugo 調用 Pandoc 執行檔時會傳遞以下 CLI 標誌:

--mathjax

reStructuredText

使用 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 的外部渲染器

原生渲染器比外部渲染器更快速。