Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 9 additions & 2 deletions lib/jekyll-toc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down