在文章页面显示当前大纲
# toc 辅助函数
解析内容中的标题标签 (h1~h6) 并插入目录。
<%- toc(str, [options]) %>
参数 | 描述 | 默认值 |
---|---|---|
class | Class 名称 | toc |
list_number | 显示编号 | true |
max_depth | 生成 TOC 的最大深度 | 6 |
min_depth | 生成 TOC 的最小深度 | 1 |
示例:
<%- toc(page.content) %>
# 在主题里添加代码
themes/hollow/layout/_partial/article-full.ejs
<!-- 页面文章目录-->
<div id="toc" class="hidden-xs hidden-sm hidden-md">
<%- toc(item.more, {list_number: false}) %>
</div>
1
2
3
4
2
3
4
# 在主题里添加css
themes/hollow/source/css/article.styl
// 文章目录css
#toc
position fixed
font-size 0.8em
color color-link
width 150px
top 200px
left 10px
.toc
ol
padding-left 14px
.toc-item
margin-bottom 10px
.toc-child
margin-top 10px
.toc-link
color #333333
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17