@@ -124,6 +124,8 @@ const docsBase = Astro.site
124124 </div >
125125 </div >
126126
127+ { requestedSlug && <script is :inline define :vars = { { slug: requestedSlug , isRoot: isRoot }} >window.__docsSlug = slug; window.__isRoot = isRoot;</script >}
128+
127129 <script is:inline define:vars ={ { isRoot , docsBase }} >
128130 document.addEventListener('DOMContentLoaded', function () {
129131 const sections = document.querySelectorAll('section.doc-section');
@@ -132,6 +134,7 @@ const docsBase = Astro.site
132134 const sidebar = document.getElementById('sidebar');
133135 const overlay = document.getElementById('overlay');
134136 const searchBox = document.getElementById('searchBox');
137+ const isRoot = window.__isRoot !== false;
135138 const prefersReducedMotion = !window.matchMedia('(prefers-reduced-motion: no-preference)').matches;
136139
137140 /* Mobile menu toggle */
@@ -147,37 +150,52 @@ const docsBase = Astro.site
147150 menuToggle.setAttribute('aria-expanded', String(isOpen));
148151 });
149152 overlay.addEventListener('click', closeMenu);
150- navItems.forEach(function (item) {
151- item.addEventListener('click', closeMenu);
152- });
153153 }
154154
155- /* Auto-scroll to hash section (root only) */
156- if (isRoot && window.location.hash) {
157- const targetId = window.location.hash.slice(1);
158- const target = document.getElementById(targetId);
159- if (target) {
160- setTimeout(function () {
161- target.scrollIntoView({ behavior: prefersReducedMotion ? 'auto' : 'smooth' });
162- }, 100);
155+ /* Auto-scroll to section (root only) */
156+ if (isRoot) {
157+ const targetSlug = window.__docsSlug;
158+ const hash = window.location.hash;
159+ const sectionId = targetSlug || (hash && hash.length > 1 ? hash.slice(1) : null);
160+ if (sectionId) {
161+ const target = document.getElementById(sectionId);
162+ if (target) {
163+ setTimeout(function () {
164+ target.scrollIntoView({ behavior: prefersReducedMotion ? 'auto' : 'smooth' });
165+ }, 100);
166+ }
163167 }
164168 }
165169
166- /* Scrollspy (root + multi-section only) */
170+ /* Scrollspy + nav click (root + multi-section only) */
167171 if (isRoot && sections.length > 1) {
168172 const observer = new IntersectionObserver(
169173 function (entries) {
170174 entries.forEach(function (entry) {
171175 if (entry.isIntersecting) {
172176 navItems.forEach(function (item) {
173- item.classList.toggle('active', item.getAttribute('data-nav-id') === entry.target.id);
177+ var isActive = item.getAttribute('data-nav-id') === entry.target.id;
178+ item.classList.toggle('active', isActive);
179+ if (isActive) {
180+ item.scrollIntoView({ behavior: prefersReducedMotion ? 'auto' : 'smooth', block: 'nearest' });
181+ }
174182 });
175183 }
176184 });
177185 },
178186 { root: null, rootMargin: '-80px 0px -60% 0px', threshold: 0 }
179187 );
180188 sections.forEach(function (section) { observer.observe(section); });
189+
190+ navItems.forEach(function (item) {
191+ item.addEventListener('click', function () {
192+ if (window.innerWidth <= 768 && menuToggle && sidebar && overlay) {
193+ sidebar.classList.remove('open');
194+ overlay.classList.remove('open');
195+ menuToggle.setAttribute('aria-expanded', 'false');
196+ }
197+ });
198+ });
181199 }
182200
183201 /* Search filter (root only) */
0 commit comments