-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
884 lines (765 loc) · 31.8 KB
/
index.html
File metadata and controls
884 lines (765 loc) · 31.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Documentation Book</title>
<!-- Marked.js for Markdown rendering -->
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<!-- Mermaid.js for diagrams -->
<script src="https://cdn.jsdelivr.net/npm/mermaid@10.6.1/dist/mermaid.min.js"></script>
<!-- Highlight.js for syntax highlighting -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/styles/github.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/highlight.min.js"></script>
<!-- Table of Contents generator -->
<script src="https://cdn.jsdelivr.net/npm/markdown-toc@1.2.0/dist/markdown-toc.min.js"></script>
<style>
:root {
--sidebar-width: 280px;
--header-height: 60px;
--primary-color: #0366d6;
--text-color: #24292e;
--border-color: #e1e4e8;
--bg-color: #ffffff;
--sidebar-bg: #f6f8fa;
--code-bg: #f6f8fa;
--font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
--font-mono: SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace;
}
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: var(--font-sans);
line-height: 1.6;
color: var(--text-color);
background-color: var(--bg-color);
display: flex;
min-height: 100vh;
}
/* Header */
#header {
position: fixed;
top: 0;
left: var(--sidebar-width);
right: 0;
height: 60px;
background-color: var(--bg-color);
border-bottom: 1px solid var(--border-color);
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 2em;
z-index: 90;
}
#project-name {
font-size: 1.4em;
font-weight: 600;
color: var(--primary-color);
}
#search-container {
position: relative;
width: 300px;
}
#search {
width: 100%;
padding: 8px 12px;
padding-right: 32px;
border: 1px solid var(--border-color);
border-radius: 6px;
font-size: 0.9em;
transition: border-color 0.2s, box-shadow 0.2s;
}
#search:focus {
outline: none;
border-color: var(--primary-color);
box-shadow: 0 0 0 3px rgba(3, 102, 214, 0.1);
}
#search-container::after {
content: '⌕';
position: absolute;
right: 10px;
top: 50%;
transform: translateY(-50%);
color: #6a737d;
pointer-events: none;
}
/* Sidebar */
#sidebar {
width: var(--sidebar-width);
background-color: var(--sidebar-bg);
border-right: 1px solid var(--border-color);
height: 100vh;
position: fixed;
overflow-y: auto;
padding: 20px;
z-index: 100;
top: 0;
}
#sidebar h2 {
font-size: 1.2em;
margin-bottom: 1em;
padding-bottom: 0.5em;
border-bottom: 1px solid var(--border-color);
}
#toc {
font-size: 0.9em;
}
#toc ul {
list-style: none;
padding-left: 1em;
}
#toc a {
color: var(--text-color);
text-decoration: none;
display: block;
padding: 4px 0;
transition: color 0.2s;
}
#toc a:hover,
#toc a.active {
color: var(--primary-color);
font-weight: 600;
}
#toc a.active {
background-color: rgba(3, 102, 214, 0.1);
border-radius: 3px;
padding: 2px 6px;
margin: 0 -6px;
}
#toc .toc-h1 { margin-left: 0; font-weight: 600; }
#toc .toc-h2 { margin-left: 1em; }
#toc .toc-h3 { margin-left: 2em; font-size: 0.9em; }
#toc .toc-h4 { margin-left: 3em; font-size: 0.85em; }
#toc .toc-h5 { margin-left: 4em; font-size: 0.8em; }
#toc .toc-h6 { margin-left: 5em; font-size: 0.75em; }
/* Main content */
#main {
flex: 1;
margin-left: var(--sidebar-width);
margin-top: 60px; /* Account for header height */
max-width: 900px;
padding: 2em 3em;
}
/* Loading indicator */
.loading {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
font-size: 1.2em;
}
.spinner {
border: 3px solid rgba(0, 0, 0, 0.1);
border-radius: 50%;
border-top: 3px solid var(--primary-color);
width: 24px;
height: 24px;
animation: spin 1s linear infinite;
margin-right: 10px;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
/* Markdown content */
.markdown-body {
line-height: 1.8;
}
.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
margin-top: 1.5em;
margin-bottom: 0.8em;
font-weight: 600;
line-height: 1.25;
position: relative;
padding-top: 1em;
}
.markdown-body h1:not(:first-child) {
border-top: 1px solid var(--border-color);
padding-top: 1.5em;
margin-top: 2em;
}
.markdown-body h1 { font-size: 2em; }
.markdown-body h2 { font-size: 1.5em; }
.markdown-body h3 { font-size: 1.25em; }
.markdown-body h4 { font-size: 1em; }
.markdown-body h5 { font-size: 0.875em; }
.markdown-body h6 { font-size: 0.85em; color: #6a737d; }
.markdown-body p {
margin-top: 0;
margin-bottom: 1em;
}
.markdown-body ul,
.markdown-body ol {
padding-left: 2em;
margin-top: 0;
margin-bottom: 1em;
}
.markdown-body li {
margin-bottom: 0.5em;
}
.markdown-body code {
background-color: var(--code-bg);
border-radius: 3px;
padding: 0.2em 0.4em;
font-family: var(--font-mono);
font-size: 85%;
}
.markdown-body pre {
background-color: var(--code-bg);
border-radius: 6px;
padding: 16px;
overflow: auto;
line-height: 1.45;
margin-bottom: 1.5em;
}
.markdown-body pre code {
background-color: transparent;
padding: 0;
border-radius: 0;
}
.search-highlight {
background-color: #ffeb3b;
padding: 0 2px;
border-radius: 3px;
font-weight: bold;
}
/* Style for search matches in TOC */
#toc a.search-match {
background-color: rgba(255, 235, 59, 0.2);
border-left: 3px solid #ffeb3b;
padding-left: 5px;
margin-left: -8px;
}
/* Ensure TOC items are properly spaced when filtered */
#toc li {
margin: 4px 0;
}
/* Style for no results message */
#no-results {
padding: 20px;
text-align: center;
color: #6a737d;
font-style: italic;
}
.markdown-body blockquote {
border-left: 0.25em solid #dfe2e5;
color: #6a737d;
padding: 0 1em;
margin: 0 0 1.5em 0;
}
.markdown-body table {
border-collapse: collapse;
width: 100%;
margin-bottom: 1.5em;
display: block;
overflow: auto;
}
.markdown-body table th,
.markdown-body table td {
border: 1px solid #dfe2e5;
padding: 6px 13px;
}
.markdown-body table tr {
background-color: #fff;
border-top: 1px solid #c6cbd1;
}
.markdown-body table tr:nth-child(2n) {
background-color: #f6f8fa;
}
/* File indicators */
.file-section {
position: relative;
}
.file-path {
position: absolute;
right: 0;
top: 0.5em;
font-size: 0.7em;
color: #6a737d;
background: #f6f8fa;
padding: 2px 8px;
border-radius: 12px;
font-family: var(--font-mono);
}
/* Responsive design */
@media (max-width: 1024px) {
:root {
--sidebar-width: 250px;
}
#main {
padding: 1.5em;
}
}
@media (max-width: 768px) {
body {
flex-direction: column;
}
#sidebar {
position: static;
width: 100%;
height: auto;
max-height: 40vh;
border-right: none;
border-bottom: 1px solid var(--border-color);
}
#main {
margin-left: 0;
padding: 1em;
}
}
</style>
</head>
<body>
<div id="sidebar">
<h2>Table of Contents</h2>
<div id="toc"></div>
</div>
<header id="header">
<div id="project-name">Docker Platform</div>
<div id="search-container">
<input type="text" id="search" placeholder="Search documentation...">
</div>
</header>
<div id="main">
<div class="loading">
<div class="spinner"></div>
<span>Loading documentation...</span>
</div>
<div id="content" class="markdown-body" style="display: none;"></div>
</div>
<script>
// Configuration
const API_URL = 'data/file-system.json';
// DOM Elements
const contentEl = document.getElementById('content');
const loadingEl = document.querySelector('.loading');
const tocEl = document.getElementById('toc');
// Load and process file system
async function loadDocumentation() {
try {
// Show loading state
contentEl.style.display = 'none';
loadingEl.style.display = 'flex';
// Load file system
const response = await fetch(API_URL);
const fileSystem = await response.json();
// Extract and sort markdown files
const markdownFiles = [];
extractMarkdownFiles(fileSystem, markdownFiles);
// Sort files by path (alphabetical order)
markdownFiles.sort((a, b) => a.path.localeCompare(b.path));
// Load and render all markdown files
await renderMarkdownFiles(markdownFiles);
// Generate table of contents
generateTOC();
// Hide loading state, show content
loadingEl.style.display = 'none';
contentEl.style.display = 'block';
// Apply syntax highlighting
document.querySelectorAll('pre code').forEach((block) => {
hljs.highlightElement(block);
});
// Scroll to hash if present in URL
if (window.location.hash) {
const id = window.location.hash.substring(1);
const element = document.getElementById(id);
if (element) {
element.scrollIntoView();
}
}
} catch (error) {
console.error('Error loading documentation:', error);
loadingEl.innerHTML = `
<div style="color: #cb2431; text-align: center; padding: 2em;">
<h2>Error Loading Documentation</h2>
<p>${error.message}</p>
<p>Make sure to run <code>generate_structure.py</code> first.</p>
</div>
`;
}
}
// Recursively extract all markdown files from the file system
function extractMarkdownFiles(node, result = []) {
if (!node) return;
if (node.type === 'file' && node.name.endsWith('.md')) {
result.push({
name: node.name,
path: node.path,
content: node.content || ''
});
} else if (node.children) {
for (const child of node.children) {
extractMarkdownFiles(child, result);
}
}
}
// Render all markdown files to the page
async function renderMarkdownFiles(files) {
let html = '';
for (const file of files) {
try {
// Add file section with path indicator
html += `
<div class="file-section">
<div class="file-path" title="${file.path}">${file.path}</div>
${marked.parse(file.content || '')}
</div>
<hr style="margin: 2em 0; border: 0; border-top: 1px dashed #e1e4e8;">
`;
} catch (error) {
console.error(`Error rendering ${file.path}:`, error);
html += `
<div class="file-section">
<h2>Error Loading: ${file.name}</h2>
<pre>${error.message}</pre>
</div>
`;
}
}
contentEl.innerHTML = html;
}
// Generate table of contents from headings
function generateTOC() {
const headings = contentEl.querySelectorAll('h1, h2, h3, h4, h5, h6');
let tocHtml = '<ul>';
let currentLevel = 1;
headings.forEach((heading, index) => {
// Skip file path indicators
if (heading.classList.contains('file-path')) return;
const level = parseInt(heading.tagName.substring(1));
const id = `heading-${index}`;
// Set ID for anchor links
heading.id = id;
// Add TOC entry
if (level > currentLevel) {
tocHtml += '<ul>'.repeat(level - currentLevel);
} else if (level < currentLevel) {
tocHtml += '</li></ul>'.repeat(currentLevel - level);
} else {
tocHtml += '</li>';
}
tocHtml += `<li class="toc-h${level}"><a href="#${id}">${heading.textContent}</a>`;
currentLevel = level;
});
// Close any open lists
tocHtml += '</li></ul>'.repeat(currentLevel - 1);
tocHtml += '</ul>';
tocEl.innerHTML = tocHtml;
}
// Initialize Mermaid
function initMermaid() {
if (typeof mermaid !== 'undefined') {
mermaid.initialize({
startOnLoad: true,
theme: 'default',
securityLevel: 'loose',
fontFamily: 'var(--font-sans)',
themeCSS: `
.markdown-body .mermaid {
background: white;
padding: 1.5em;
border-radius: 6px;
margin: 1.5em 0;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.markdown-body .mermaid svg {
max-width: 100%;
height: auto;
}
`
});
// Re-render any mermaid diagrams in the content
mermaid.init(undefined, '.language-mermaid');
}
}
// Handle scroll to highlight current section in TOC
function handleScroll() {
const sections = Array.from(document.querySelectorAll('h1[id], h2[id], h3[id], h4[id], h5[id], h6[id]'));
const scrollPosition = window.scrollY + 100; // Add some offset
// Reset all active links
document.querySelectorAll('#toc a').forEach(link => {
link.classList.remove('active');
});
// Find the current section in view
let currentSection = null;
let maxVisibleHeight = -Infinity;
sections.forEach(section => {
const rect = section.getBoundingClientRect();
const sectionTop = rect.top + window.scrollY;
const sectionHeight = rect.height;
// Calculate how much of the section is visible
const visibleHeight = Math.min(rect.bottom, window.innerHeight) - Math.max(rect.top, 0);
const visibleRatio = visibleHeight / sectionHeight;
// If this section is more visible than previous ones, make it current
if (visibleRatio > 0 && visibleHeight > maxVisibleHeight) {
maxVisibleHeight = visibleHeight;
currentSection = '#' + section.id;
} else if (visibleHeight === maxVisibleHeight && currentSection) {
// If equal visibility, prefer the earlier section
const currentTop = document.querySelector(currentSection)?.getBoundingClientRect().top || 0;
if (rect.top < currentTop) {
currentSection = '#' + section.id;
}
}
});
// If no section is in view, find the one just above the viewport
if (!currentSection && sections.length > 0) {
for (let i = 0; i < sections.length; i++) {
const section = sections[i];
if (section.offsetTop > scrollPosition) {
currentSection = '#' + (i > 0 ? sections[i-1].id : sections[0].id);
break;
}
}
if (!currentSection) {
currentSection = '#' + sections[sections.length - 1].id;
}
}
// Highlight the corresponding TOC link
if (currentSection) {
const activeLink = document.querySelector(`#toc a[href="${currentSection}"]`);
if (activeLink && !activeLink.classList.contains('active')) {
// Remove active class from all links first
document.querySelectorAll('#toc a.active').forEach(link => {
link.classList.remove('active');
});
activeLink.classList.add('active');
// Scroll the TOC to center the active link
const toc = document.getElementById('toc');
const tocRect = toc.getBoundingClientRect();
const linkRect = activeLink.getBoundingClientRect();
const linkTop = activeLink.offsetTop;
const linkHeight = linkRect.height;
const tocHeight = toc.offsetHeight;
// Calculate the position to center the active link
const scrollTop = linkTop - (tocHeight / 2) + (linkHeight / 2);
// Only scroll if the link is not already in view
if (linkTop < toc.scrollTop || (linkTop + linkHeight) > (toc.scrollTop + tocHeight)) {
// Use smooth scrolling if the distance is large, instant for small adjustments
const behavior = Math.abs(toc.scrollTop - scrollTop) > 500 ? 'smooth' : 'auto';
toc.scrollTo({
top: Math.max(0, scrollTop),
behavior: behavior
});
}
}
}
}
// Throttle scroll events for better performance
let scrollTimeout;
function throttledScroll() {
if (!scrollTimeout) {
scrollTimeout = setTimeout(() => {
handleScroll();
scrollTimeout = null;
}, 50); // Adjust the throttle time as needed (in milliseconds)
}
}
// Search functionality
function setupSearch() {
const searchInput = document.getElementById('search');
if (!searchInput) return;
// Store original TOC structure
let originalTocStructure = null;
// Function to show all content sections
function showAllSections() {
document.querySelectorAll('.markdown-body > *').forEach(el => {
el.style.display = '';
});
const noResults = document.getElementById('no-results');
if (noResults) noResults.remove();
}
// Function to build TOC from filtered items
function buildFilteredToc(searchTerm) {
const toc = document.getElementById('toc');
if (!searchTerm) {
// Restore original TOC if search is empty
if (originalTocStructure) {
toc.innerHTML = '';
toc.appendChild(originalTocStructure.cloneNode(true));
}
showAllSections();
return true; // Indicates we're showing all content
}
const searchLower = searchTerm.toLowerCase();
let hasMatches = false;
// Create a new container for filtered items
const filteredToc = document.createElement('div');
filteredToc.style.display = 'none'; // Start hidden
// Helper function to check if an element has matching text
function hasMatchingText(element) {
return element.textContent.toLowerCase().includes(searchLower);
}
// Process each top-level item
Array.from(originalTocStructure.children).forEach(item => {
const link = item.querySelector('a');
if (!link) return;
// Check if this item has matching text
if (hasMatchingText(item)) {
const clone = item.cloneNode(true);
filteredToc.appendChild(clone);
hasMatches = true;
}
});
// Update the TOC
toc.innerHTML = '';
if (hasMatches) {
filteredToc.style.display = ''; // Show if we have matches
toc.appendChild(filteredToc);
// Highlight matching text in TOC
document.querySelectorAll('#toc a').forEach(link => {
const text = link.textContent;
const regex = new RegExp(`(${searchTerm})`, 'gi');
link.innerHTML = text.replace(regex, '<span class="search-highlight">$1</span>');
});
} else {
// Completely clear the TOC when no matches
toc.innerHTML = '';
}
return hasMatches; // Return whether we found any matches
}
// Function to filter content based on search
function filterContent(searchTerm, hasTocMatches = true) {
if (!searchTerm) {
showAllSections();
return;
}
// Clear any existing no-results message
const existingNoResults = document.getElementById('no-results');
if (existingNoResults) {
existingNoResults.remove();
}
// If no TOC matches, hide all content and show no results
if (!hasTocMatches) {
document.querySelectorAll('.markdown-body > *').forEach(el => {
el.style.display = 'none';
});
const noResults = document.createElement('div');
noResults.id = 'no-results';
noResults.textContent = 'No results found';
noResults.style.padding = '20px';
noResults.style.textAlign = 'center';
noResults.style.color = '#6a737d';
document.querySelector('.markdown-body').prepend(noResults);
return;
}
const sections = document.querySelectorAll('.markdown-body > h1, .markdown-body > h2, .markdown-body > h3, .markdown-body > h4, .markdown-body > h5, .markdown-body > h6');
let foundResults = false;
const searchLower = searchTerm.toLowerCase();
// First, hide all sections
document.querySelectorAll('.markdown-body > *').forEach(el => {
el.style.display = 'none';
});
// Show sections that match the search
sections.forEach(section => {
const sectionText = section.textContent.toLowerCase();
if (sectionText.includes(searchLower)) {
// Show this section and all content until the next section
let next = section.nextElementSibling;
section.style.display = '';
// Highlight matching text in the section
const regex = new RegExp(`(${searchTerm})`, 'gi');
section.innerHTML = section.textContent.replace(regex, '<span class="search-highlight">$1</span>');
// Show content until the next section
while (next && !next.matches('h1, h2, h3, h4, h5, h6')) {
next.style.display = '';
// Highlight in content
if (next.textContent.toLowerCase().includes(searchLower)) {
next.innerHTML = next.textContent.replace(regex, '<span class="search-highlight">$1</span>');
}
next = next.nextElementSibling;
}
foundResults = true;
}
});
// Show no results message if needed
const noResults = document.getElementById('no-results');
if (!foundResults) {
if (!noResults) {
const noResultsEl = document.createElement('div');
noResultsEl.id = 'no-results';
noResultsEl.textContent = 'No results found in content';
noResultsEl.style.padding = '20px';
noResultsEl.style.textAlign = 'center';
noResultsEl.style.color = '#6a737d';
document.querySelector('.markdown-body').prepend(noResultsEl);
}
} else if (noResults) {
noResults.remove();
}
}
// Store original TOC structure on first search
searchInput.addEventListener('focus', () => {
if (!originalTocStructure) {
originalTocStructure = document.getElementById('toc').cloneNode(true);
}
}, { once: true });
// Handle search input
searchInput.addEventListener('input', (e) => {
const searchTerm = e.target.value.trim();
const hasMatches = buildFilteredToc(searchTerm);
filterContent(searchTerm, hasMatches);
});
// Handle search clear (when clicking the X in the search box)
searchInput.addEventListener('search', (e) => {
if (!e.target.value) {
buildFilteredToc('');
}
});
}
// Initialize
document.addEventListener('DOMContentLoaded', () => {
loadDocumentation().then(() => {
setupSearch();
initMermaid();
// Add scroll event listener after content is loaded
window.addEventListener('scroll', throttledScroll);
// Initial check in case the page loads with a hash
setTimeout(() => {
handleScroll();
// Check for hash in URL and scroll to it
if (window.location.hash) {
const element = document.querySelector(window.location.hash);
if (element) {
element.scrollIntoView();
setTimeout(handleScroll, 100);
}
}
}, 500);
// Also handle hash changes (when clicking TOC links)
window.addEventListener('hashchange', () => {
const hash = window.location.hash;
if (hash) {
const element = document.querySelector(hash);
if (element) {
// Small delay to ensure the DOM is updated
setTimeout(() => {
element.scrollIntoView({ behavior: 'smooth' });
handleScroll();
}, 50);
}
}
});
// Reinitialize Mermaid when content is loaded dynamically
const observer = new MutationObserver((mutations) => {
if (document.querySelector('pre code.language-mermaid')) {
initMermaid();
}
});
observer.observe(document.body, {
childList: true,
subtree: true
});
});
});
</script>
</body>
</html>