hugo-theme-anubis2/layouts/partials/toc.html

41 lines
994 B
HTML

{{ $toc := true }}
{{ if isset .Params "toc" }}
{{ $toc = .Params.toc }}
{{ else }}
{{ $toc = ge .WordCount .Site.Params.tocWordCount }}
{{ if and (isset .Site.Params "toc") (not (.Site.Params.toc)) }}
{{ $toc = false }}
{{ end }}
{{ 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>
var toc = document.querySelector(".toc");
if (toc) {
toc.addEventListener("click", function () {
if (event.target.tagName !== "A") {
event.preventDefault();
if (this.open) {
this.open = false;
this.classList.remove("expanded");
} else {
this.open = true;
this.classList.add("expanded");
}
}
});
}
</script>