Grouping categories in hexo

别来无恙 提交于 2019-12-25 01:44:51

问题


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:


  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.


来源:https://stackoverflow.com/questions/46194621/grouping-categories-in-hexo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!