一. 修改post.ejs文件

不同的主题位置不一,Ctrl+f 找post.content ,应该就能找到。

notepad批量打开文件见:Notepad 插件&技巧&特殊技巧

在文件中添加如下代码至<%- post.content %>之前。

1
2
3
4
5
6
7
8
<!--Table of Contents begin-->
<% if(post.toc == true){ %>
<div id="toc" class="toc-article">
<strong class="toc-title">目录</strong>
<%- toc(post.content,{list_number:false}) %>
</div>
<% } %>
<!--Table of Contents end -->

二. 在对应.css.tyle文件中增加样式

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
/*toc*/
.toc-article {
background #eee;
border: 1px solid #bbb;
border-radius: 10px;
margin: 1.5em 0 0.3em 1.5em;
padding: 1.2em 1em 0 1em;
max-width: 28%
}
.toc-title {
font-size: 120%
}
#toc {
line-height: 1em;
font-size: 0.9em;
float: right
}
.toc {
padding: 0;
margin: 1em;
line-height: 1.8em
}
/* 增加无序列表的小圆点 还要修改上面第6行 li包括ol和ul,所以把li改为ol即可,toc的锅也是没想到*/
/* 原版: li{ */
ol{
list-style-type: none
}
.toc-child {
margin-left: 1em
}

三. 在文章中添加 toc: true

1
2
3
4
5
6
---
title: sample
date: sample
name: 97年的顽石
toc: true
---

运行一下,完