Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Table of contents in blog articles #76

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions exampleSite/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ pluralizeListTitles = false
customCSS = ["default"]
customJS = ["default"]

# Decide if blog articles have a toc
# Note: You can deactivate a toc for a single article via setting parameter tocActivated = "false" in article config
tocIfNecessary = true
# Min. number of words in article after which toc gets generated
tocWordCount = 500

# Disqus will take priority over Staticman (github.com/eduardoboucas/staticman)
# due to its ease of use. Feel free to check out both and decide what you would
# prefer to use. See Staticman.yml for additional settings.
Expand Down
10 changes: 10 additions & 0 deletions layouts/partials/toc.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!--
Taken from Hugo manual: Show toc after site has word count larger than some value
toc generation can be stopped by adding a parameter tocFalse to the content
-->

{{ if and (.Site.Params.tocIfNecessary) (gt .WordCount .Site.Params.tocWordCount) (ne .Params.tocActivated "false") }}
<aside>
{{.TableOfContents}}
</aside>
{{ end }}
1 change: 1 addition & 0 deletions layouts/post/content-single.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

{{ .Render "featured" }}
<div id="content">
{{ partial "toc" . }}
{{ .Content }}
</div>

Expand Down