Skip to content

Commit f586819

Browse files
brabojclaude
andcommitted
refactor: move mobile ToC into hamburger menu
Replace standalone MobileToc component with an "On this page" section inside the hamburger nav panel. JS clones h2 links from the existing sidebar-toc at runtime. Tapping a section link closes the panel and scrolls to the heading. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 9e3b62c commit f586819

5 files changed

Lines changed: 50 additions & 86 deletions

File tree

.claude/worktrees/agent-abc53eb2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit a9d1faee4bb53b601f763e5aff2d543242ec49ab

astro-site/src/components/Header.astro

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,31 @@ const base = import.meta.env.BASE_URL;
9090
navToggle.setAttribute("aria-expanded", "false");
9191
siteTabs.classList.remove("open");
9292
});
93+
94+
// Populate "On this page" section from the sidebar ToC
95+
const sidebarToc = document.querySelector(".sidebar-toc");
96+
if (sidebarToc) {
97+
const topLinks = sidebarToc.querySelectorAll(":scope > ul > li");
98+
if (topLinks.length > 0) {
99+
const label = document.createElement("div");
100+
label.className = "nav-toc-label";
101+
label.textContent = "On this page";
102+
siteTabs.appendChild(label);
103+
104+
topLinks.forEach((li) => {
105+
const source = li.querySelector(":scope > a, :scope > details > summary > a");
106+
if (source) {
107+
const link = document.createElement("a");
108+
link.href = source.getAttribute("href");
109+
link.textContent = source.textContent;
110+
link.className = "nav-toc-link";
111+
link.addEventListener("click", () => {
112+
navToggle.setAttribute("aria-expanded", "false");
113+
siteTabs.classList.remove("open");
114+
});
115+
siteTabs.appendChild(link);
116+
}
117+
});
118+
}
119+
}
93120
</script>

astro-site/src/components/MobileToc.astro

Lines changed: 0 additions & 23 deletions
This file was deleted.

astro-site/src/layouts/DocLayout.astro

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import Header from "../components/Header.astro";
44
import TableOfContents from "../components/TableOfContents.astro";
55
import TutorialLinks from "../components/TutorialLinks.astro";
66
import Footer from "../components/Footer.astro";
7-
import MobileToc from "../components/MobileToc.astro";
87
import site from "../data/site.json";
98
109
interface Props {
@@ -67,7 +66,6 @@ const ogImage = new URL("/tutorial-git/images/og-banner.png", Astro.site);
6766
<div class="resize-handle" data-side="left"></div>
6867
<main class="content" id="main-content">
6968
<h1>{title}</h1>
70-
<MobileToc headings={headings} />
7169
<slot />
7270
</main>
7371
<div class="resize-handle" data-side="right"></div>

astro-site/src/styles/global.css

Lines changed: 22 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -572,11 +572,6 @@ a:hover {
572572
color: var(--color-fg-muted);
573573
}
574574

575-
/* Mobile ToC — hidden on desktop, shown when sidebar disappears */
576-
.mobile-toc {
577-
display: none;
578-
}
579-
580575
/* Responsive */
581576
@media (max-width: 960px) {
582577
.site-main {
@@ -588,62 +583,6 @@ a:hover {
588583
.resize-handle {
589584
display: none;
590585
}
591-
592-
.mobile-toc {
593-
display: block;
594-
margin-bottom: var(--space-lg);
595-
border: 1px solid var(--color-border);
596-
border-radius: 4px;
597-
padding: 0;
598-
position: sticky;
599-
top: 0;
600-
z-index: 10;
601-
background: var(--color-bg);
602-
}
603-
604-
.mobile-toc summary {
605-
padding: var(--space-sm) var(--space-md);
606-
font-weight: 600;
607-
font-size: var(--font-size-base);
608-
color: var(--color-fg);
609-
cursor: pointer;
610-
list-style: none;
611-
}
612-
613-
.mobile-toc summary::after {
614-
content: "\25B6";
615-
float: right;
616-
font-size: 0.7em;
617-
color: var(--color-fg-faint);
618-
transition: transform 0.15s;
619-
}
620-
621-
.mobile-toc[open] summary::after {
622-
transform: rotate(90deg);
623-
}
624-
625-
.mobile-toc summary::-webkit-details-marker {
626-
display: none;
627-
}
628-
629-
.mobile-toc ul {
630-
list-style: none;
631-
padding: 0 var(--space-md) var(--space-sm);
632-
}
633-
634-
.mobile-toc li {
635-
padding: var(--space-xs) 0;
636-
}
637-
638-
.mobile-toc a {
639-
color: var(--color-link);
640-
text-decoration: none;
641-
font-size: var(--font-size-sm);
642-
}
643-
644-
.mobile-toc a:hover {
645-
text-decoration: underline;
646-
}
647586
}
648587

649588
@media (max-width: 768px) {
@@ -686,6 +625,28 @@ a:hover {
686625
background: rgba(255, 255, 255, 0.1);
687626
}
688627

628+
.nav-toc-label {
629+
padding: var(--space-sm) var(--space-md);
630+
font-size: var(--font-size-sm);
631+
font-weight: 600;
632+
color: rgba(255, 255, 255, 0.5);
633+
text-transform: uppercase;
634+
letter-spacing: 0.05em;
635+
border-top: 1px solid rgba(255, 255, 255, 0.1);
636+
}
637+
638+
.nav-toc-link {
639+
padding: var(--space-xs) var(--space-md) var(--space-xs) var(--space-lg);
640+
font-size: var(--font-size-sm);
641+
color: rgba(255, 255, 255, 0.8);
642+
text-decoration: none;
643+
display: block;
644+
}
645+
646+
.nav-toc-link:hover {
647+
background: rgba(255, 255, 255, 0.1);
648+
}
649+
689650
.content {
690651
padding: var(--space-lg) var(--space-md);
691652
}

0 commit comments

Comments
 (0)