HUGO
Menu
GitHub 87548 stars Mastodon

Hugo 配置分类法

Hugo 配置分类法。

默认配置定义了两个 分类法categoriestags

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 设置来禁用 taxonomyterm 页面 类型

disableKinds:
- taxonomy
- term
disableKinds = ['taxonomy', 'term']
{
   "disableKinds": [
      "taxonomy",
      "term"
   ]
}

请参阅 分类法 部分以获取更多信息。


Last updated: January 1, 0001
Improve this page