Hugo 配置分類法
Hugo 配置分類法。
默認配置定義了兩個 分類法:categories 和 tags。
taxonomies:
category: categories
tag: tags
[taxonomies]
category = 'categories'
tag = 'tags'
{
"taxonomies": {
"category": "categories",
"tag": "tags"
}
}
創建分類法時:
- 對鍵使用單數形式(例如
category)。 - 對值使用復數形式(例如
categories)。
然後在 front matter 中使用該值作為鍵:
---
categories:
- vegetarian
- gluten-free
tags:
- appetizer
- main course
title: Example
---+++
categories = ['vegetarian', 'gluten-free']
tags = ['appetizer', 'main course']
title = 'Example'
+++{
"categories": [
"vegetarian",
"gluten-free"
],
"tags": [
"appetizer",
"main course"
],
"title": "Example"
}
如果您不期望將給定分類法的多個 術語 分配給內容頁面,您可以對鍵和值都使用單數形式:
taxonomies:
author: author
[taxonomies]
author = 'author'
{
"taxonomies": {
"author": "author"
}
}
然後在 front matter 中:
---
author:
- Robert Smith
title: Example
---+++
author = ['Robert Smith']
title = 'Example'
+++{
"author": [
"Robert Smith"
],
"title": "Example"
}
上面的示例說明,即使只有一個術語,值仍然作為數組提供。
添加新分類法時,您必須顯式定義默認分類法以保留它們:
taxonomies:
author: author
category: categories
tag: tags
[taxonomies]
author = 'author'
category = 'categories'
tag = 'tags'
{
"taxonomies": {
"author": "author",
"category": "categories",
"tag": "tags"
}
}
要禁用分類法系統,請在站點配置的根目錄中使用 disableKinds 設置來禁用 taxonomy 和 term 頁面 類型。
disableKinds:
- taxonomy
- term
disableKinds = ['taxonomy', 'term']
{
"disableKinds": [
"taxonomy",
"term"
]
}
請參閱 分類法 部分以獲取更多信息。