Skip to content

Commit f117529

Browse files
Enhance command TOC styling and add active section tracking
Improved the appearance and responsiveness of the command table of contents (TOC) with updated CSS, including better dark mode support and mobile layout. Added JavaScript to highlight the active TOC link based on scroll position, improving navigation and user experience.
1 parent 89e7583 commit f117529

File tree

2 files changed

+121
-13
lines changed

2 files changed

+121
-13
lines changed

static/css/command-docs.css

Lines changed: 67 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -327,44 +327,98 @@ article table tbody tr:hover {
327327

328328
/* Table of Contents */
329329
.command-toc {
330+
display: flex;
331+
flex-wrap: wrap;
332+
align-items: center;
333+
gap: 0.5rem;
330334
margin-bottom: 2rem;
331-
font-size: 1.1rem;
332-
color: #59636e;
333-
text-align: center;
334-
display: block;
335-
width: 100%;
335+
padding: 0.875rem 1.25rem;
336+
background: #f6f8fa;
337+
border: 1px solid #d1d9e0;
338+
border-left: 3px solid #22C55E;
339+
border-radius: 8px;
340+
font-size: 0.9rem;
336341
}
337342

338343
.command-toc .toc-label {
339-
font-weight: 600;
340-
color: #1f2328;
344+
font-weight: 500;
345+
color: #59636e;
346+
font-size: 0.8rem;
347+
text-transform: uppercase;
348+
letter-spacing: 0.03em;
349+
margin-right: 0.5rem;
341350
}
342351

343352
.command-toc a {
344-
color: #0969da;
353+
display: inline-block;
354+
padding: 0.375rem 0.75rem;
355+
color: #1f2328;
345356
text-decoration: none;
346-
transition: color 0.15s ease;
357+
border-radius: 6px;
358+
transition: all 0.15s ease;
359+
font-weight: 500;
360+
background: transparent;
347361
}
348362

349363
.command-toc a:hover {
350364
color: #22C55E;
351-
text-decoration: underline;
365+
background: rgba(34, 197, 94, 0.1);
366+
text-decoration: none;
367+
}
368+
369+
.command-toc a:focus {
370+
outline: 2px solid #22C55E;
371+
outline-offset: 2px;
372+
}
373+
374+
/* Active state for current section (requires JS) */
375+
.command-toc a.active {
376+
color: #22C55E;
377+
background: rgba(34, 197, 94, 0.12);
352378
}
353379

354380
.dark .command-toc {
355-
color: #9198a1;
381+
background: #1c2128;
382+
border-color: #30363d;
383+
border-left-color: #22C55E;
356384
}
357385

358386
.dark .command-toc .toc-label {
359-
color: #e6edf3;
387+
color: #9198a1;
360388
}
361389

362390
.dark .command-toc a {
363-
color: #60A5FA;
391+
color: #e6edf3;
364392
}
365393

366394
.dark .command-toc a:hover {
367395
color: #22C55E;
396+
background: rgba(34, 197, 94, 0.15);
397+
}
398+
399+
.dark .command-toc a.active {
400+
color: #22C55E;
401+
background: rgba(34, 197, 94, 0.18);
402+
}
403+
404+
/* Mobile: stack vertically */
405+
@media (max-width: 640px) {
406+
.command-toc {
407+
flex-direction: column;
408+
align-items: flex-start;
409+
gap: 0.25rem;
410+
padding: 0.75rem 1rem;
411+
}
412+
413+
.command-toc .toc-label {
414+
margin-bottom: 0.5rem;
415+
margin-right: 0;
416+
}
417+
418+
.command-toc a {
419+
width: 100%;
420+
padding: 0.5rem 0.75rem;
421+
}
368422
}
369423

370424
/* Section anchor - positioned above heading so scroll lands at heading */

themes/dbatools2025/layouts/commands/single.html

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@
8787

8888
// Add copy buttons to code blocks
8989
addCopyButtons();
90+
91+
// Initialize TOC active state tracking
92+
initTocActiveState();
9093
});
9194

9295
function addCopyButtons() {
@@ -170,6 +173,57 @@
170173

171174
return cleanLines.join('\n');
172175
}
176+
177+
function initTocActiveState() {
178+
const toc = document.querySelector('.command-toc');
179+
if (!toc) return;
180+
181+
const tocLinks = toc.querySelectorAll('a[href^="#"]');
182+
if (tocLinks.length === 0) return;
183+
184+
// Get all section anchors
185+
const sections = [];
186+
tocLinks.forEach(link => {
187+
const id = link.getAttribute('href').substring(1);
188+
const anchor = document.getElementById(id);
189+
if (anchor) {
190+
sections.push({ id, anchor, link });
191+
}
192+
});
193+
194+
if (sections.length === 0) return;
195+
196+
// Throttled scroll handler
197+
let ticking = false;
198+
function updateActiveLink() {
199+
const scrollPos = window.scrollY + 120; // Offset for fixed header
200+
201+
let activeSection = sections[0];
202+
for (const section of sections) {
203+
if (section.anchor.offsetTop <= scrollPos) {
204+
activeSection = section;
205+
}
206+
}
207+
208+
tocLinks.forEach(link => link.classList.remove('active'));
209+
if (activeSection) {
210+
activeSection.link.classList.add('active');
211+
}
212+
}
213+
214+
window.addEventListener('scroll', () => {
215+
if (!ticking) {
216+
requestAnimationFrame(() => {
217+
updateActiveLink();
218+
ticking = false;
219+
});
220+
ticking = true;
221+
}
222+
});
223+
224+
// Set initial active state
225+
updateActiveLink();
226+
}
173227
</script>
174228

175229
<style>

0 commit comments

Comments
 (0)