【问题标题】:Grouping categories in hexo在 hexo 中对类别进行分组
【发布时间】:2017-11-24 16:43:26
【问题描述】:

我想在 hexo 中对类别进行分组。虽然 hexo 帮助器可以列出我所有的类别,但我想对嵌套类别进行分组。

我的问题是在两个层面上,首先,您如何表示前端的子类别。换句话说,我将如何将子类别 [motosport、板球、篮球、曲棍球] 添加到以下前沿问题中。 运动是主要类别

categories:
  - sports

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

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

或者有没有更好的方法/功能?

【问题讨论】:

  • 这个主题支持 childCategories 你可以看看它是怎么做的github.com/LouisBarranqueiro/hexo-theme-tranquilpeak/blob/…
  • 我检查了它,但我仍然有一个问题,因为没有实际示例说明您如何在实际项目中挂钩该支持。我的意思是,你如何写前面的子类别?
  • 在 Categories-filter.js 上尝试 parent-categories: MyCategory this.dataCategory = 'category'; this.dataParentCategories = 'parent-categories';
  • 嗯,在 yaml 中。看,我想在 category 运动和 subcategory 板球下发表一篇文章。怎么说呢?
  • 那么您将如何在主题中引用它以使其适用于所有帖子?

标签: javascript themes hexo yaml-front-matter


【解决方案1】:
  1. Hexo v3.3.9 中添加了hierarchical categories feature。需要通过this commit 更新hexo/node_modules/hexo/lib/models/post.js(或更新,如果存在)。并设置这样的类别(*.md):

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-14
    • 1970-01-01
    • 2020-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多