From 9335f396d067b6c4b828fbcf57e9ab9a40c83785 Mon Sep 17 00:00:00 2001 From: gandalf3 Date: Thu, 14 Mar 2019 01:06:52 -0700 Subject: [PATCH 1/3] Add option to enable toc by default Also make `toc_only` return nothing when toc is disabled. This might be a more controversial change, but I can't think of a case where outputting two copies of the entire content would be desired. --- lib/jekyll-toc.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/jekyll-toc.rb b/lib/jekyll-toc.rb index 6a7d70c..cf77c64 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 From 81b1503641a8fb265feced22067e57d98cef79f5 Mon Sep 17 00:00:00 2001 From: gandalf3 Date: Thu, 14 Mar 2019 01:27:20 -0700 Subject: [PATCH 2/3] Document global enable option --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) 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, From fa4019c4355ae58fdb1d26ba2004da5692d998d5 Mon Sep 17 00:00:00 2001 From: gandalf3 Date: Thu, 14 Mar 2019 01:28:29 -0700 Subject: [PATCH 3/3] Remove a bit of python which accidentally snuck in --- lib/jekyll-toc.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jekyll-toc.rb b/lib/jekyll-toc.rb index cf77c64..5436d07 100644 --- a/lib/jekyll-toc.rb +++ b/lib/jekyll-toc.rb @@ -41,7 +41,7 @@ def toc_enabled? if enabled_on_page == nil return enabled_site_wide - else: + else return page_specific end end