hexo 中的分组类别

Grouping categories in hexo

我想在 hexo 中对类别进行分组。虽然 hexo <% list_categories %> 帮助程序列出了我所有的类别,但我想正确地对嵌套类别进行分组。

我的问题有两个层面,第一,你如何在front matter中表示子类别。换句话说,我如何将子类别 [motosport、cricket、basketball、hockey] 添加到以下 front matter 中。 运动是主要类别

categories:
  - sports

二,我如何枚举所有类别及其每个子项。我还用这个代码吗

<%- list_categories(site.categories, { options}); %>

还是有更好的way/function?

  1. Hexo v3.3.9 added hierarchical categories feature. Need to update hexo/node_modules/hexo/lib/models/post.js by this commit 中(或更新版本,如果存在)。并像这样设置类别(在 *.md 中):

    categories:
    - [sport, motosport]
    - [sport, cricket]
    - [sport, basketball]
    - [sport, hockey]
    
  2. <%- list_categories() %> 没有任何参数枚举 parents 和他们的孩子已经在分层列表中; <%- list_categories(site.categories, {depth: 1}) %> 仅枚举站点总数的 parents(运动)等。现在的完整选项 here