部分

只要节中的目录(或子目录)content包含 _index.md文件,就会创建一个节。如果目录不包含_index.md文件,则不会创建任何部分,但该目录中的 Markdown 文件仍会创建页面(称为孤立页面)。

主页(即,当用户浏览到您的 时显示的页面base_url)是一个部分,无论您是否在目录_index.md的根目录下添加文件,都会创建该部分content如果您不在_index.md内容目录中创建文件,则此主要内容部分将没有任何内容或元数据。如果您想添加内容或元数据,您可以 在目录_index.md的根目录下添加一个文件content并像编辑任何其他 _index.md文件一样编辑它;然后您的index.html模板将可以访问该内容和元数据。

节目录中的任何非 Markdown 文件都会添加到assets节的集合中,如 内容概述中所述。然后可以使用相关链接在 Markdown 文件中使用这些文件。

🔗起草

就像可以通过draft在前面设置选项来起草页面部分一样。默认情况下不这样做。当一个部分被起草时,它的后代如页面、小节和资产将不会被处理,除非标志--drafts被传递。draft请注意,如果其父部分之一已起草,即使没有状态的页面也不会被处理。

🔗前言

目录中的文件_index.md定义该部分的内容和元数据。要设置元数据,请将 front matter 添加到文件中。

TOML front matter 是一组嵌入文件中的元数据,位于文件的开头,由三重加号 ( +++) 括起来。

关闭后+++,您可以添加内容,这些内容将被解析为 Markdown 并通过变量提供给您的模板section.content

尽管前面的变量都不是强制性的,但打开和关闭+++是必需的。

请注意,尽管鼓励使用 TOML,但也支持 YAML front matter 以简化遗留内容的移植。在这种情况下,嵌入的元数据必须包含在三重负数 ( ---) 中。

_index.md这是一个包含所有可用变量的示例。下面提供的值是默认值。

title = ""

description = ""

# A draft section is only loaded if the `--drafts` flag is passed to `zola build`, `zola serve` or `zola check`.
draft = false

# Used to sort pages by "date", "update_date", "title", "title_bytes", "weight", "slug" or "none". See below for more information.
sort_by = "none"

# Used by the parent section to order its subsections.
# Lower values have higher priority.
weight = 0

# Template to use to render this section page.
template = "section.html"

# The given template is applied to ALL pages below the section, recursively.
# If you have several nested sections, each with a page_template set, the page
# will always use the closest to itself.
# However, a page's own `template` variable will always have priority.
# Not set by default.
page_template =

# This sets the number of pages to be displayed per paginated page.
# No pagination will happen if this isn't set or if the value is 0.
paginate_by = 0

# If set, this will be the path used by the paginated page. The page number will be appended after this path.
# The default is page/1.
paginate_path = "page"

# If set, there will pagination will happen in a reversed order.
paginate_reversed = false

# This determines whether to insert a link for each header like the ones you can see on this site if you hover over
# a header.
# The default template can be overridden by creating an `anchor-link.html` file in the `templates` directory.
# This value can be "left", "right", "heading" or "none".
# "heading" means the full heading becomes the text of the anchor.
insert_anchor_links = "none"

# If set to "true", the section pages will be in the search index. This is only used if
# `build_search_index` is set to "true" in the Zola configuration file.
in_search_index = true

# If set to "true", the section homepage is rendered.
# Useful when the section is used to organize pages (not used directly).
render = true

# This determines whether to redirect when a user lands on the section. Defaults to not being set.
# Useful for the same reason as `render` but when you don't want a 404 when
# landing on the root section page.
# Example: redirect_to = "documentation/content/overview"
redirect_to =

# If set to "true", the section will pass its pages on to the parent section. Defaults to `false`.
# Useful when the section shouldn't split up the parent section, like
# sections for each year under a posts section.
transparent = false

# Use aliases if you are moving content but want to redirect previous URLs to the
# current one. This takes an array of paths, not URLs.
aliases = []

# If set to "true", a feed file will be generated for this section at the
# section's root path. This is independent of the site-wide variable of the same
# name. The section feed will only include posts from that respective feed, and
# not from any other sections, including sub-sections under that section.
generate_feed = false

# Your own data.
[extra]

请记住,任何配置选项仅适用于直接页面,不适用于子部分的页面。

🔗分页

要为某个部分的页面启用分页,请设置paginate_by为正数。有关模板中可用变量的更多信息,请参阅 分页模板文档。

您还可以page/1通过设置paginate_path默认为page.

🔗排序

Zola 模板迭代页面或部分以显示给定目录中的所有页面/部分是很常见的。考虑一个非常简单的例子:一个blog包含三个文件的目录:blog/Post_1.md, blog/Post_2.mdblog/Post_3.md. 要遍历这些帖子并创建指向这些帖子的链接列表,一个简单的模板可能如下所示:

{% for post in section.pages %}
  <h1><a href="{{ post.permalink }}">{{ post.title }}</a></h1>
{% endfor %}

这将按照相应部分sort_by在页面中设置的变量指定的顺序遍历帖子。可以为_index.md变量sort_by指定几个值:dateupdate_date titletitle_bytesweightslugnone如果sort_by未设置,页面将按顺序排序none,这不适用于已排序的内容。

任何缺少需要排序的数据的页面都将被忽略并且不会呈现。例如,如果页面缺少日期变量且其部分设置为sort_by = "date",则该页面将被忽略。如果发生这种情况,终端将警告您。

如果多个页面具有相同的日期/重量/顺序,它们的永久链接将用于根据字母顺序打破平局。

🔗排序页面

front sort_by-matter 变量可以有以下值:

🔗date

这将按字段对所有页面进行排序date,从最新的(在列表的顶部)到最旧的(在列表的底部)。每个页面都将获取page.lowerpage.higher变量,这些变量分别包含日期较早和较晚的页面。

🔗update_date

date与除了它会考虑updated页面的任何日期之外相同。

🔗title

这将按照词法排序箱中title定义的自然词法顺序按字段对所有页面进行排序每个页面都将获取变量,这些变量分别包含具有上一个和下一个标题的页面。natural_lexical_cmppage.lowerpage.higher

例如,这是一个自然的词汇顺序:“bachata、BART、bolero、μ-kernel、meter、Métro、Track-2、Track-3、Track-13、underground”。注意特殊字符和数字是如何合理排序的。

🔗title_bytes

title除了它直接使用字节进行排序外,与其他相同。自然排序将非 ASCII 字符视为最接近的 ASCII 字符。对于具有不同字符集的语言,这可能会导致意外结果。例如,瑞典字母表的最后三个字符 åäö 将被自然排序视为 aao。在那种情况下,标准字节顺序排序可能更合适。

🔗weight

这将按照它们的weight字段对所有页面进行排序,从最轻的权重(在列表的顶部)到最重的(在列表的底部)。每个页面分别获取page.lowerpage.higher包含权重较轻和较重的页面的变量。

🔗slug

这将按照自然词汇顺序对页面或部分进行排序。

🔗反向排序

遍历页面时,您可能希望使用 Terareverse过滤器,它会反转页面的顺序。例如,使用reverse过滤器后,按重量排序的页面将从最轻(顶部)到最重(底部)排序;按日期排序的页面将从最旧(在顶部)到最新(在底部)排序。

reversepage.lower对/没有影响page.higher

如果该部分已分页,paginate_reversed=true则应设置相关部分的前面内容,而不是使用过滤器。

🔗排序小节

排序部分不太灵活:部分只能按 排序weight,并且没有指向较重/较轻部分的变量。

默认情况下,最轻(最低weight)的子部分将位于列表的顶部,最重(最高weight)的子部分将位于底部;过滤reverse器颠倒这个顺序。

注意:与页面不同,永久链接不会用于打破同等权重部分之间的联系。因此,如果weight您的部分的变量未设置(或者如果以产生联系的方式设置),那么您的部分将按 随机顺序排序。此外,该顺序是在构建时确定的,并且会随着每次站点重建而改变。因此,如果您有任何机会迭代您的部分,您应该始终为它们分配不同的权重。