From 1cd8e7f0d510b97dfc2c3314c36d957383162a8f Mon Sep 17 00:00:00 2001
From: Jacky Zhao <j.zhao2k19@gmail.com>
Date: Sun, 09 Mar 2025 22:06:36 +0000
Subject: [PATCH] feat: support non-singleton table of contents

---
 quartz/components/scripts/toc.inline.ts |   13 ++++++-------
 1 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/quartz/components/scripts/toc.inline.ts b/quartz/components/scripts/toc.inline.ts
index a518c10..a63da8d 100644
--- a/quartz/components/scripts/toc.inline.ts
+++ b/quartz/components/scripts/toc.inline.ts
@@ -25,16 +25,15 @@
 }
 
 function setupToc() {
-  const toc = document.getElementById("toc")
-  if (toc) {
-    const content = toc.nextElementSibling as HTMLElement | undefined
-    if (!content) return
-    toc.addEventListener("click", toggleToc)
-    window.addCleanup(() => toc.removeEventListener("click", toggleToc))
+  for (const toc of document.querySelectorAll(".toc")) {
+    const button = toc.querySelector(".toc-header")
+    const content = toc.querySelector(".toc-content")
+    if (!button || !content) return
+    button.addEventListener("click", toggleToc)
+    window.addCleanup(() => button.removeEventListener("click", toggleToc))
   }
 }
 
-window.addEventListener("resize", setupToc)
 document.addEventListener("nav", () => {
   setupToc()
 

--
Gitblit v1.10.0