采用目录结构是一种简便可行的方案。

最常用的文件管理策略,就是利用文件系统目录结构(树形结构 directory-tree)。 同样,为了便于管理大量的日志文件,采用目录结构是一种简便可行的方案。hexo-auto-category根据日志文件(Markdown)所在文件目录自动分类,即自动生成markdown的front-matter中的categories变量。

# 安装插件

npm install hexo-auto-category --save

在站点根目录下的_config.yml添加:

#  Generate categories from directory-tree
# Dependencies: https://github.com/xu-song/hexo-auto-category
# depth: the depth of directory-tree you want to generate, should > 0
auto_category:
 enable: true
 depth:
1
2
3
4
5
6

如果只想生成第一级目录分类,可以设置depth属性,比如:

auto_category:
 enable: true
 depth: 1
 
1
2
3
4

# 文件配置

修改主题里的 categories.ejs文件. 如果没有就新建一个,并且在source目录建立 categories/index.md

---
title: 文章分类
date: 2018-06-11 10:13:21
type: "categories"  
layout: "categories"
comments: false

---
1
2
3
4
5
6
7
8

categories.ejs文件内容.

<div class="fenlei">
      <div style="height: 100px"></div>
      <%- list_categories({class: "category-tree"}) %>
  </div>
  <style>
      .fenlei{
          position: fixed;
          top: 10px;
          right: 10px;
      }
      .category-tree-list {
          padding-left: 15px;
      }
      .category-tree-list-item {
          font-size: 13px;
          margin-bottom:5px;

      }
      .category-tree-list-link{
      }

      .category-tree-list-count {
          color: #2aa198;
          display: none;
      }
      .category-tree-list-child{
          margin-top:5px;
          padding-left: 16px;
      }

  </style>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

# 编译 & 部署

hexo clean && hexo g && hexo d

更新时间: 2024/8/2 17:52:13