diff --git a/README.md b/README.md index 2f065d0..d0e74db 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,15 @@ toc: true --- ``` +Or set `enable_by_default: true` in `_config.yml` to enable for all posts. + +```yml +toc: + enable_by_default: true +``` + +With this option, setting `toc: false` in a post's frontmatter to disable the TOC on that post. + ## Usage There are three Liquid filters, which can be applied to HTML content, diff --git a/lib/jekyll-toc.rb b/lib/jekyll-toc.rb index 6a7d70c..5436d07 100644 --- a/lib/jekyll-toc.rb +++ b/lib/jekyll-toc.rb @@ -16,7 +16,7 @@ module Jekyll # Jekyll Table of Contents filter plugin module TableOfContentsFilter def toc_only(html) - return html unless toc_enabled? + return '' unless toc_enabled? ::Jekyll::TableOfContents::Parser.new(html, toc_config).build_toc end @@ -36,7 +36,14 @@ def toc(html) private def toc_enabled? - @context.registers[:page]['toc'] == true + enabled_site_wide = @context.registers[:site].config['toc']['enable_by_default'] == true + enabled_on_page = @context.registers[:page]['toc'] + + if enabled_on_page == nil + return enabled_site_wide + else + return page_specific + end end def toc_config