HUGO
Menu
GitHub 87548 stars Mastodon

Hugo 頁面 Bundle

使用頁面 bundle 將一個或多個資源與內容邏輯關聯。

介紹

頁面 bundle 是一個封裝內容和相關資源的目錄。

舉例來說,這個站點有一個"about"頁面和一個"privacy"頁面:

content/
├── about/
│   ├── index.md
│   └── welcome.jpg
└── privacy.md

“about"頁面是一個頁面 bundle。它通過 bundle 將資源與內容邏輯關聯。頁面 bundle 內的資源是 page resources,可以通過 Page 對象上的 Resources 方法訪問。

頁面 bundle 要麼是 leaf bundles(葉 bundle),要麼是 branch bundles(分支 bundle)。

leaf bundle
leaf bundle 是一個包含 index.md 文件和零個或多個資源的目錄。類似於物理的葉子,leaf bundle 在分支的末端。它沒有後代。
branch bundle
branch bundle 是一個包含 _index.md 文件和零個或多個資源的目錄。類似於物理的分支,branch bundle 可能有後代,包括 leaf bundles 和其他 branch bundles。有或沒有 _index.md 文件的頂層目錄也是 branch bundles。這包括首頁。

在上面的定義和下面的示例中,索引文件的擴展名取決於 content format。例如,Markdown 內容使用 index.md,HTML 內容使用 index.html,AsciiDoc 內容使用 index.adoc 等。

比較

頁面 bundle 特性因 bundle 類型而異。

Leaf bundle Branch bundle
Index file index.md _index.md
Example content/about/index.md content/posts/_index.md
Page kinds page homesectiontaxonomyterm
Template types single homesectiontaxonomyterm
Descendant pages 零個或多個
Resource location 與索引文件相鄰或在嵌套子目錄中 與 leaf bundles 相同,但不包括後代 bundles
Resource types pageimagevideo page 外的所有類型

具有 resource type page 的文件包括用 Markdown、HTML、AsciiDoc、Pandoc、reStructuredText 和 Emacs Org Mode 編寫的內容。在 leaf bundle 中(不包括索引文件),這些文件只能作為頁面資源訪問。在 branch bundle 中,這些文件只能作為內容頁面訪問。

Leaf bundles

leaf bundle 是一個包含 index.md 文件和零個或多個資源的目錄。類似於物理的葉子,leaf bundle 在分支的末端。它沒有後代。

content/
├── about
│   └── index.md
├── posts
│   ├── my-post
│   │   ├── content-1.md
│   │   ├── content-2.md
│   │   ├── image-1.jpg
│   │   ├── image-2.png
│   │   └── index.md
│   └── my-other-post
│       └── index.md
└── another-section
    ├── foo.md
    └── not-a-leaf-bundle
        ├── bar.md
        └── another-leaf-bundle
            └── index.md

上面的示例中有四個 leaf bundles:

about
此 leaf bundle 不包含任何頁面資源。
my-post
此 leaf bundle 包含一個索引文件、兩個 resource typepage 的資源,以及兩個 resource type 為 image 的資源。
  • content-1, content-2

    這些是 resource type 為 page 的資源,可以通過 Page 對象上的 Resources 方法訪問。Hugo 不會將這些渲染為單獨的頁面。

  • image-1, image-2

    這些是 resource type 為 image 的資源,可以通過 Page 對象上的 Resources 方法訪問

my-other-post
此 leaf bundle 不包含任何頁面資源。
another-leaf-bundle
此 leaf bundle 不包含任何頁面資源。

content 目錄內的任何深度創建 leaf bundles,但 leaf bundle 不能包含另一個 bundle。Leaf bundles 沒有後代。

Branch bundles

branch bundle 是一個包含 _index.md 文件和零個或多個資源的目錄。類似於物理的分支,branch bundle 可能有後代,包括 leaf bundles 和其他 branch bundles。有或沒有 _index.md 文件的頂層目錄也是 branch bundles。這包括首頁。

content/
├── branch-bundle-1/
│   ├── _index.md
│   ├── content-1.md
│   ├── content-2.md
│   ├── image-1.jpg
│   └── image-2.png
├── branch-bundle-2/
│   ├── a-leaf-bundle/
│   │   └── index.md
│   └── _index.md
└── _index.md

上面的示例中有三個 branch bundles:

home page
此 branch bundle 包含一個索引文件、兩個後代 branch bundles,沒有資源。
branch-bundle-1
此 branch bundle 包含一個索引文件、兩個 resource typepage 的資源,以及兩個 resource type 為 image 的資源。
branch-bundle-2
此 branch bundle 包含一個索引文件和一個 leaf bundle。

content 目錄內的任何深度創建 branch bundles。Branch bundles 可能有後代。

Headless bundles

使用 front matter 中的 build options 創建未發布的 leaf 或 branch bundle,其內容和資源可以包含在其他頁面中。


Last updated: January 1, 0001
Improve this page