Grouping categories in hexo

2019-08-27 17:01发布

I would like to group categories in hexo. While the hexo <% list_categories %> helper lists all my categories alright, I would like to group nested categories right.

My question is on two levels, first, how do you represent the subcategories in the front matter. In other words, how would I add the subcategories [motosport, cricket, basketball, hockey] into the following front matter. sports is the main category

categories:
  - sports

Two, how do I enumerate through all categories and each of their children. Do I still use this code

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

or is there a better way/function?

1条回答
The star\"
2楼-- · 2019-08-27 17:27
  1. In Hexo v3.3.9 added hierarchical categories feature. Need to update hexo/node_modules/hexo/lib/models/post.js by this commit (or newer if exists). And set categories like this (in *.md):

    categories:
    - [sport, motosport]
    - [sport, cricket]
    - [sport, basketball]
    - [sport, hockey]
    
  2. <%- list_categories() %> without any parameters enumerate parents and their childs already in hierarchical list; <%- list_categories(site.categories, {depth: 1}) %> enum only parents (sport) of site total, etc. Full options for now here.
查看更多
登录 后发表回答