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