add: expandable ToC

This commit is contained in:
Junyi Hou 2024-03-04 19:15:27 +08:00
parent e319a2414e
commit 528a25fed5
4 changed files with 47 additions and 9 deletions

View file

@ -1,9 +1,19 @@
{{ $toc := and ($.Site.Params.toc) (ge .WordCount $.Site.Params.tocWordCount) }}
{{ if isset .Params "toc" }}
{{ $toc = .Params.toc }}
{{ $toc := and ($.Site.Params.toc) (ge .WordCount $.Site.Params.tocWordCount) }} {{ if isset .Params "toc" }} {{ $toc = .Params.toc }} {{ end }} {{ if $toc }}
<details class="toc">
<summary>Table of Contents</summary>
<div class="inner">{{ .TableOfContents }}</div>
</details>
{{ end }}
{{ if $toc }}
{{ .TableOfContents }}
{{ end }}
<script>
document.querySelector(".toc").addEventListener("click", function () {
event.preventDefault();
if (this.open) {
this.open = false;
this.classList.remove("expanded");
} else {
this.open = true;
this.classList.add("expanded");
}
});
</script>