天天看點

在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就行了!