diff options
author | zwbetz-gh <zwbetz@gmail.com> | 2021-09-12 22:24:53 +0300 |
---|---|---|
committer | zwbetz-gh <zwbetz@gmail.com> | 2021-09-12 22:24:53 +0300 |
commit | 87e1a8608f44d46f6cc34fc54a4ddadbd2999433 (patch) | |
tree | ae7d5957cc1b8c2dadd6185144c8377527d2cf21 /layouts | |
parent | b87a99af1fe064a574ba385a9f11334f4296f314 (diff) |
use hugo's toc
Diffstat (limited to 'layouts')
-rw-r--r-- | layouts/partials/toc.html | 19 | ||||
-rw-r--r-- | layouts/post/single.html | 6 |
2 files changed, 5 insertions, 20 deletions
diff --git a/layouts/partials/toc.html b/layouts/partials/toc.html index 55a2ccb..cdb0d7c 100644 --- a/layouts/partials/toc.html +++ b/layouts/partials/toc.html @@ -1,19 +1,6 @@ -{{ $headings := findRE "<h2.*?>(.|\n])+?</h2>" .Content }} -{{ if ge (len $headings) 2 }} +{{ if eq .Params.toc true }} <nav class="toc" aria-labelledby="toc-heading"> - <h2 id="toc-heading">{{ T "table_of_contents" }}</h2> - <ol> - {{ range $headings }} - <li> - {{ $id := findRE "id=\".*\"" . }} - {{ $id = index $id 0 }} - {{ $id = strings.TrimPrefix "id=\"" $id }} - {{ $id = strings.TrimSuffix "\"" $id }} - <a href="#{{ $id }}"> - {{ . | htmlUnescape | plainify }} - </a> - </li> - {{ end }} - </ol> + <strong id="toc-heading">{{ T "table_of_contents" }}</strong> + {{ .TableOfContents }} </nav> {{ end }} diff --git a/layouts/post/single.html b/layouts/post/single.html index 9003db6..38512f6 100644 --- a/layouts/post/single.html +++ b/layouts/post/single.html @@ -35,10 +35,8 @@ </ul> </div> {{ end }} - - {{ if ne .Params.toc false }} - {{ partial "toc" . }} - {{ end }} + + {{ partial "toc.html" . }} {{ .Content }} </main> |