diff --git a/quartz/components/TableOfContents.tsx b/quartz/components/TableOfContents.tsx index 485f434..da6eece 100644 --- a/quartz/components/TableOfContents.tsx +++ b/quartz/components/TableOfContents.tsx @@ -29,8 +29,7 @@ const TableOfContents: QuartzComponent = ({
-
+
{fileData.toc.map((tocEntry) => (
  • @@ -72,7 +71,7 @@ const LegacyTableOfContents: QuartzComponent = ({ fileData, cfg }: QuartzCompone return null } return ( -
    +

    {i18n(cfg.locale).components.tableOfContents.title}

    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 toggleToc(this: HTMLElement) { } 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() diff --git a/quartz/components/styles/legacyToc.scss b/quartz/components/styles/legacyToc.scss index 7a98f34..3513e9f 100644 --- a/quartz/components/styles/legacyToc.scss +++ b/quartz/components/styles/legacyToc.scss @@ -1,4 +1,4 @@ -details#toc { +details.toc { & summary { cursor: pointer; diff --git a/quartz/components/styles/toc.scss b/quartz/components/styles/toc.scss index d1feca6..42aa35c 100644 --- a/quartz/components/styles/toc.scss +++ b/quartz/components/styles/toc.scss @@ -6,18 +6,18 @@ overflow-y: hidden; flex: 0 1 auto; - &:has(button#toc.collapsed) { + &:has(button.toc-header.collapsed) { flex: 0 1 1.2rem; } } @media all and not ($mobile) { - .toc { + .toc-header { display: flex; } } -button#toc { +button.toc-header { background-color: transparent; border: none; text-align: left; @@ -44,7 +44,7 @@ button#toc { } } -#toc-content { +.toc-content { list-style: none; position: relative;