内容组织
页面包
Hugo 0.32
版本发布了页面相关的图像和其他资源打包成“页面包”。
这些术语是相互关联的,您还需要阅读关于 页面资源 和 图像处理 的内容才能全面了解。
content/
├── blog/
│ ├── hugo-is-cool/
│ │ ├── images/
│ │ │ ├── funnier-cat.jpg
│ │ │ └── funny-cat.jpg
│ │ ├── cats-info.md
│ │ └── index.md
│ ├── posts/
│ │ ├── post1.md
│ │ └── post2.md
│ ├── 1-landscape.jpg
│ ├── 2-sunset.jpg
│ ├── _index.md
│ ├── content-1.md
│ └── content-2.md
├── 1-logo.png
└── _index.md
上面的文件树显示了三个包。请注意,主页包不能包含其他内容页面,尽管允许其他文件(图像等)。
内容源的组织
在 Hugo 中,您的内容应该以反映渲染网站的方式进行组织。
虽然 Hugo 支持任何级别的嵌套内容,但顶级级别(即 content/<DIRECTORIES>
)在 Hugo 中是特殊的,被认为是用于确定布局等的內容类型。要了解更多关于章节的信息,包括如何嵌套它们,请参阅 章节 。
无需任何额外配置,以下内容将自动生效:
.
└── content
└── about
| └── index.md // <- https://example.org/about/
├── posts
| ├── firstpost.md // <- https://example.org/posts/firstpost/
| ├── happy
| | └── ness.md // <- https://example.org/posts/happy/ness/
| └── secondpost.md // <- https://example.org/posts/secondpost/
└── quote
├── first.md // <- https://example.org/quote/first/
└── second.md // <- https://example.org/quote/second/
Hugo 中的路径分解
以下内容演示了当 Hugo 网站渲染时,您的内容组织与输出 URL 结构之间的关系。这些示例假设您 使用漂亮的 URL ,这是 Hugo 的默认行为。这些示例还假设您的 站点配置文件 中有一个键值对 baseURL = "https://example.org/"
。
首页: _index.md
_index.md
在 Hugo 中具有特殊作用。它允许您向主页、章节、分类和术语页面添加前置 matter 和内容。
您可以为您的主页创建一个 _index.md
,并在您的每个内容章节、分类和术语中创建一个。以下显示了 _index.md
的典型位置,它将包含 Hugo 网站上“文章”章节列表页面的内容和前置 matter:
. url
. ⊢--^-⊣
. path slug
. ⊢--^-⊣⊢---^---⊣
. file path
. ⊢------^------⊣
content/posts/_index.md
构建时,这将输出到以下目标位置,并具有关联的值:
url ("/posts/")
⊢-^-⊣
baseurl section ("posts")
⊢--------^---------⊣⊢-^-⊣
permalink
⊢----------^-------------⊣
https://example.org/posts/index.html
章节 可以嵌套任意深度。要理解的重要一点是,为了使章节树完全可导航,至少最底层的章节必须包含一个内容文件(即 _index.md
)。
章节中的单个页面
您每个章节中的单个内容文件将由 单个模板 渲染。这是一个章节内单个“文章”的示例:
path ("posts/my-first-hugo-post.md")
. ⊢-----------^------------⊣
. section slug
. ⊢-^-⊣⊢--------^----------⊣
content/posts/my-first-hugo-post.md
当 Hugo 构建您的站点时,内容将输出到以下目标位置:
url ("/posts/my-first-hugo-post/")
⊢------------^----------⊣
baseurl section slug
⊢--------^--------⊣⊢-^--⊣⊢-------^---------⊣
permalink
⊢--------------------^---------------------⊣
https://example.org/posts/my-first-hugo-post/index.html
路径详解
以下概念提供了更多关于项目组织与构建网站输出时 Hugo 默认行为之间关系的见解。
section
默认内容类型由内容项存储的章节决定。 section
由项目 content
目录中的位置决定。 section
不能在前置 matter 中指定或覆盖。
slug
slug
是 URL 路径的最后一个段,由文件名定义,并且可以选择由前置 matter 中的 slug
值覆盖。详情请参阅 URL 管理 。
path
内容的 path
由章节到文件的路径决定。文件 path
- 基于内容位置的路径,并且
- 不包括 slug
url
url
是整个 URL 路径,由文件路径定义,并且可以选择由前置 matter 中的 url
值覆盖。详情请参阅 URL 管理 。