天天看点

在Hexo NexT主题中关闭指定文章的Table of Contents(TOC)

问题描述

NexT主题中在每篇文章单独的post页面,侧边栏会根据文章的多级标题自动生成Table of Contents。不过对于有些文章,我想关闭这项功能,但是我发现在文章的Front-matter中并没有这个选项!

看了下代码,解决了这个问题。记录一下!

解决办法

使用toc

首先我们肯定要打开toc,进入

主题

下的

_config.yml

文件,下面是我的配置:

toc:
  enable: true
  # Automatically add list number to toc.
  number: true
  # If true, all words will placed on next lines if header width longer then sidebar width.
  wrap: true
  # If true, all level of TOC in a post will be displayed, rather than the activated part of it.
  expand_all: false
  # Maximum heading depth of generated toc.
  max_depth: 6
           

部分关闭toc

  1. 进入主题中的文件

    sidebar.swig

    vim ./layout/_macro/sidebar.swig 
               
  2. 找到:
    在Hexo NexT主题中关闭指定文章的Table of Contents(TOC)
    添加一个判断条件

    page.etoc

  3. 最后在写文章的时候在Front-matter中加上:

    上面的意思是显示toc,如果是false就是不显示!

  4. 最后提一个建议:

    进入hexo的

    scaffolds

    文件夹,找到文件

    post.md

    ,修改如下:
    在Hexo NexT主题中关闭指定文章的Table of Contents(TOC)
    以后直接hexo new 文件名 就可以自动生成这个模板,省去了自己去写。想不用toc的时候直接改成false就行了!