Merge pull request #186 from SandaruKasa/toc

Table of Contents
This commit is contained in:
Dmitry Kolosov 2023-07-06 13:02:48 +03:00 committed by GitHub
commit 70b24a8171
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 0 deletions

View File

@ -12,6 +12,7 @@ Anubis is a simple minimalist theme for [Hugo blog engine](https://gohugo.io/).
- Pagination
- Multiple taxonomies: tags, categories, authors
- Archive
- Table of Contents
- Open Graph and Twitter Cards support
- Mobile support
- Social icons
@ -99,6 +100,8 @@ params:
readMore: false # show read more button
readNextPosts: 5 # show 5 related posts, 0 by default
disableSummary: false
toc: true # display Table of Contents
tocWordCount: 300 # ...when a post is longer than 300 words
copyCodeButton: true # true by default
rssAsSocialIcon: true
mathjax: false # https://www.mathjax.org/
@ -165,6 +168,15 @@ Options:
- `dark` - dark theme by default, can be switched by user to light theme and back. Theme settings are saved for user
- `auto` - theme based on user system settings by default, can be switched by user to dark/light theme. Theme settings are saved for user (by default in example sites)
### Table of Contents
If `toc` param in `params` section of the config file is set to `true`,
Table of Contents is generated for every post that is at least `tocWordCount`
words long (`0` by default, also belongs to the `params` section of the config).
This behavior can be overridden on per-post basis
by setting `toc` to either `true` or `false` in the front matter of a post.
### Social icons
#### Predefined icons
To add icon from predefined list, add to `params.social` config:

View File

@ -15,6 +15,7 @@
{{ partial "post-language-switcher.html" . }}
</header>
</div>
{{ partial "toc.html" .}}
<div class="content e-content">
{{ .Content }}
</div>

View File

@ -0,0 +1,9 @@
{{ $toc := and ($.Site.Params.toc) (ge .WordCount $.Site.Params.tocWordCount) }}
{{ if isset .Params "toc" }}
{{ $toc = .Params.toc }}
{{ end }}
{{ if $toc }}
{{ .TableOfContents }}
{{ end }}