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

36 lines
891 B
HTML
Raw Normal View History

2024-03-06 06:24:28 +01:00
{{ $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 }}
2023-07-04 21:29:38 +02:00
{{ end }}
2024-03-06 06:24:28 +01:00
2024-03-04 12:44:29 +01:00
<script>
2024-03-18 09:58:35 +01:00
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");
}
2024-03-04 12:44:29 +01:00
}
2024-03-18 09:58:35 +01:00
});
}
2024-03-04 12:44:29 +01:00
</script>