Zola 内置了对分类法的支持。分类法是用户根据用户定义的类别对内容进行分组的一种方式。
想象一下,你想做一个网站来展示各种电影的信息。在这种情况下,您可以使用以下分类法:
然后在构建时,Zola 可以为每个分类法创建页面,列出所有已知术语,以及为分类法中的每个术语创建页面,列出与该术语相关的所有内容。
再次想象我们有以下电影:
- Shape of water <--- Value
- Director <--- Taxonomy
- Guillermo Del Toro <--- Term
- Genres <--- Taxonomy
- Thriller <--- Term
- Drama <--- Term
- Awards <--- Taxonomy
- Golden globe <--- Term
- Academy award <--- Term
- BAFTA <--- Term
- Release year <--- Taxonomy
- 2017 <--- Term
- The Room: <--- Value
- Director <--- Taxonomy
- Tommy Wiseau <--- Term
- Genres <--- Taxonomy
- Romance <--- Term
- Drama <--- Term
- Release Year <--- Taxonomy
- 2003 <--- Term
- Bright <--- Value
- Director <--- Taxonomy
- David Ayer <--- Term
- Genres <--- Taxonomy
- Fantasy <--- Term
- Action <--- Term
- Awards <--- Taxonomy
- California on Location Awards <--- Term
- Release Year <--- Taxonomy
- 2017 <--- Term
在此示例中,页面Release year
将包含指向 2003 年和 2017 年页面的链接,其中 2017 年页面将同时列出 Shape of Water 和 Bright。
分类法有六个变量:
name
: 将在 URL 中使用的必需字符串,通常是复数形式(即标签、类别等)paginate_by
:如果将其设置为一个数字,则每个术语页面将按此数量分页。paginate_path
: 如果设置,此路径将被分页页面使用,页码将附加在它之后。例如,默认值为 page/1。feed
:如果设置为true
,将为每个术语生成一个提要(默认为 atom)。lang
: 仅当您正在制作多语言站点并希望指明此分类法适用于哪种语言时才设置此项render
:如果设置为false
,则不会为分类法或单个术语呈现页面。插入配置文件(config.toml):
⚠️ 将分类键放在主要部分而不是[extra]
部分
示例 1:(一种语言)
taxonomies = [
{ name = "director", feed = true},
{ name = "genres", feed = true},
{ name = "awards", feed = true},
{ name = "release-year", feed = true},
]
示例 2:(多语言站点)
taxonomies = [
{name = "director", feed = true, lang = "fr"},
{name = "director", feed = true, lang = "eo"},
{name = "director", feed = true, lang = "en"},
{name = "genres", feed = true, lang = "fr"},
{name = "genres", feed = true, lang = "eo"},
{name = "genres", feed = true, lang = "en"},
{name = "awards", feed = true, lang = "fr"},
{name = "awards", feed = true, lang = "eo"},
{name = "awards", feed = true, lang = "en"},
{name = "release-year", feed = true, lang = "fr"},
{name = "release-year", feed = true, lang = "eo"},
{name = "release-year", feed = true, lang = "en"},
]
配置完成后,您可以在内容中设置分类法,Zola 会选择它们:
例子:
+++
title = "Shape of water"
date = 2019-08-15 # date of the post, not the movie
[taxonomies]
director=["Guillermo Del Toro"]
genres=["Thriller","Drama"]
awards=["Golden Globe", "Academy award", "BAFTA"]
release-year = ["2017"]
+++
以类似于部分和页面如何计算其输出路径的方式:
slugify.taxonomies
启用时( ,默认值)被 slugified"on"
然后可以通过以下路径访问分类页面:
$BASE_URL/$NAME/ (taxonomy)
$BASE_URL/$NAME/$SLUG (taxonomy entry)
请注意,分类法不区分大小写,因此具有相同 slug 的术语将被合并,例如,包含标签“example”的部分和页面将显示在与包含“Example”的分类法页面相同的分类法页面中