hugo-theme-anubis2/layouts/partials/toc.html
2024-04-09 20:03:09 +08:00

36 lines
888 B
HTML

{{ $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>
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>