Hexo NexT - Disable ToC for Specific Posts

UPDATE!!!
感谢 @rantosmic 的评论,现在最新版的 Hexo NexT 主题中可以在 Front-matter 中加入如下配置即可:

1
2
toc:
enable: false

最近借助 Hexo 搭建了自己的博客,使用的是 NexT 主题,这个主题的侧边栏会根据文章的标题生成多级目录(Table of Content)。不过对于有些页面,我不想开启这个功能,比如 About 页。

经过一番 code review 我发现了这个文件 [themes/next/layout/_macro/sidebar.swig](https://github.com/theme-next/hexo-theme-next/blob/master/layout/_macro/sidebar.swig#L13)。找到这行代码:

1
{% set display_toc = is_post and theme.toc.enable or is_page and theme.toc.enable %}

变量 display_toc 即指示了是否启用侧边栏目录,我们在其中加一个字段:

1
{% set display_toc = is_post and theme.toc.enable and !page.disable_toc or is_page and theme.toc.enable and !page.disable_toc %}

这样一来,在不想启用侧边栏目录的文章的 Front-matter 中加一行即可:

1
disable_toc: true