fix: the ToC shown on non-toc pages
This commit is contained in:
parent
ada44ff67d
commit
3d600a74c3
@ -1,10 +1,21 @@
|
|||||||
{{ $toc := and ($.Site.Params.toc) (ge .WordCount $.Site.Params.tocWordCount) }} {{ if isset .Params "toc" }} {{ $toc = .Params.toc }} {{ end }} {{ if $toc }}
|
{{ $toc := and ($.Site.Params.toc) (ge .WordCount $.Site.Params.tocWordCount) }}
|
||||||
<details class="toc noselect">
|
{{ if isset .Params "toc" }}
|
||||||
<summary>Table of Contents</summary>
|
{{ $toc = .Params.toc }}
|
||||||
<div class="inner">{{ .TableOfContents }}</div>
|
{{ end }}
|
||||||
</details>
|
|
||||||
|
|
||||||
|
{{ if $toc }}
|
||||||
|
{{ $tocContent := .TableOfContents }}
|
||||||
|
{{ if findRE "<li>" $tocContent }}
|
||||||
|
<!-- we show the toc only if we have element in .TableOfContents -->
|
||||||
|
<details class="toc noselect">
|
||||||
|
<summary>Table of Contents</summary>
|
||||||
|
<div class="inner">{{ .TableOfContents }}</div>
|
||||||
|
</details>
|
||||||
|
{{ end }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
document.querySelector(".toc").addEventListener("click", function () {
|
document.querySelector(".toc").addEventListener("click", function () {
|
||||||
if (event.target.tagName !== "A") {
|
if (event.target.tagName !== "A") {
|
||||||
|
28
layouts/partials/toc.html.rej
Normal file
28
layouts/partials/toc.html.rej
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
diff a/layouts/partials/toc.html b/layouts/partials/toc.html (rejected hunks)
|
||||||
|
@@ -1,10 +1,21 @@
|
||||||
|
-{{ $toc := and ($.Site.Params.toc) (ge .WordCount $.Site.Params.tocWordCount) }} {{ if isset .Params "toc" }} {{ $toc = .Params.toc }} {{ end }} {{ if $toc }}
|
||||||
|
-<details class="toc noselect">
|
||||||
|
- <summary>Table of Contents</summary>
|
||||||
|
- <div class="inner">{{ .TableOfContents }}</div>
|
||||||
|
-</details>
|
||||||
|
+{{ $toc := and ($.Site.Params.toc) (ge .WordCount $.Site.Params.tocWordCount) }}
|
||||||
|
+{{ if isset .Params "toc" }}
|
||||||
|
+ {{ $toc = .Params.toc }}
|
||||||
|
+{{ end }}
|
||||||
|
+
|
||||||
|
+
|
||||||
|
+{{ if $toc }}
|
||||||
|
+ {{ $tocContent := .TableOfContents }}
|
||||||
|
+ {{ if findRE "<li>" $tocContent }}
|
||||||
|
+ <!-- we show the toc only if we have element in .TableOfContents -->
|
||||||
|
+ <details class="toc noselect">
|
||||||
|
+ <summary>Table of Contents</summary>
|
||||||
|
+ <div class="inner">{{ .TableOfContents }}</div>
|
||||||
|
+ </details>
|
||||||
|
+ {{ end }}
|
||||||
|
{{ end }}
|
||||||
|
|
||||||
|
+
|
||||||
|
<script>
|
||||||
|
document.querySelector(".toc").addEventListener("click", function () {
|
||||||
|
if (event.target.tagName !== "A") {
|
Loading…
Reference in New Issue
Block a user