mirror of https://github.com/luizdepra/hugo-coder.git

John D. Rowell
2 days ago 145401dd6b9161e1316a338ca54f3a35d8d696d0
Added TOC support (#985)

### Prerequisites

Put an `x` into the box(es) that apply:

- [ ] This pull request fixes a bug.
- [x] This pull request adds a feature.
- [ ] This pull request introduces breaking change.

### Description

Adds "Table of Contents" functionality for posts. I believe this was not
implemented before, and I use it on my site.

### Issues Resolved

List any existing issues this pull request resolves.

### Checklist

Put an `x` into the box(es) that apply:

#### General

- [x] Describe what changes are being made
- [x] Explain why and how the changes were necessary and implemented
respectively
- [ ] Reference issue with `#<ISSUE_NO>` if applicable

#### Resources

- [ ] If you have changed any SCSS code, run `make release` to
regenerate all CSS files

#### Contributors

- [x] Add yourself to `CONTRIBUTORS.md` if you aren't on it already
2 files modified
1 files added
14 ■■■■■ changed files
i18n/en.toml 3 ●●●●● patch | view | raw | blame | history
layouts/_partials/toc.html 9 ●●●●● patch | view | raw | blame | history
layouts/posts/single.html 2 ●●●●● patch | view | raw | blame | history
i18n/en.toml
@@ -62,3 +62,6 @@
[link_to_heading]
other = "Link to heading"
[entry_toc]
other = "Table of Contents"
layouts/_partials/toc.html
New file
@@ -0,0 +1,9 @@
{{- $toc := default .Site.Params.Entry.toc .Params.toc -}}
{{- $tocOpen := default .Site.Params.Entry.tocOpen .Params.tocOpen -}}
{{- if $toc }}
<details class="entry__toc toc" {{ if $tocOpen }}open{{ end }}>
    <summary class="toc__title">{{- T "entry_toc" -}}</summary>
    {{ .TableOfContents }}
</details>
{{- end }}
layouts/posts/single.html
@@ -31,6 +31,8 @@
        </div>
      </header>
      {{ partial "toc.html" . }}
      <div class="post-content">
        {{ if .Params.featuredImage }}
          <img src="{{ .Params.featuredImage | relURL }}" alt="Featured image"/>