Skip to content

Commit c306e4c

Browse files
committed
fix: Replace ES module with regular script tag for GitHub Pages
- Changed from ES module import to regular script tag - Better compatibility with GitHub Pages - Simplified initialization with polling - Should fix diagram rendering issues
1 parent 29a7368 commit c306e4c

1 file changed

Lines changed: 48 additions & 68 deletions

File tree

docs_site/_layouts/default.html

Lines changed: 48 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -407,19 +407,40 @@
407407
<p><a href="https://github.com/rayraycodes/rails-accessibility-testing" style="color: white;">GitHub</a></p>
408408
</footer>
409409

410-
<!-- Mermaid.js for diagram rendering - Load at end of body for better reliability -->
411-
<script type="module">
412-
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.esm.min.mjs';
413-
414-
// Initialize Mermaid
415-
mermaid.initialize({
416-
startOnLoad: true,
417-
theme: 'default',
418-
securityLevel: 'loose',
419-
flowchart: { useMaxWidth: true },
420-
sequence: { useMaxWidth: true },
421-
gantt: { useMaxWidth: true }
422-
});
410+
<!-- Mermaid.js for diagram rendering - Use regular script for GitHub Pages compatibility -->
411+
<script src="https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.min.js"></script>
412+
<script>
413+
// Initialize Mermaid when loaded
414+
(function() {
415+
function initMermaidLib() {
416+
if (typeof mermaid !== 'undefined') {
417+
mermaid.initialize({
418+
startOnLoad: false, // We'll call run() manually
419+
theme: 'default',
420+
securityLevel: 'loose',
421+
flowchart: { useMaxWidth: true },
422+
sequence: { useMaxWidth: true },
423+
gantt: { useMaxWidth: true }
424+
});
425+
window.mermaid = mermaid;
426+
return true;
427+
}
428+
return false;
429+
}
430+
431+
// Try to initialize immediately
432+
if (!initMermaidLib()) {
433+
// If not loaded yet, wait for it
434+
const checkInterval = setInterval(() => {
435+
if (initMermaidLib()) {
436+
clearInterval(checkInterval);
437+
}
438+
}, 50);
439+
440+
// Stop checking after 5 seconds
441+
setTimeout(() => clearInterval(checkInterval), 5000);
442+
}
443+
})();
423444

424445
// Function to create fullscreen overlay
425446
function createFullscreenOverlay() {
@@ -851,69 +872,28 @@
851872
}
852873
};
853874

854-
// Wait for everything to be ready
855-
function initMermaid() {
856-
// Wait a bit for Jekyll/Kramdown to finish processing
857-
setTimeout(() => {
858-
if (typeof window.processMermaidDiagrams === 'function') {
875+
// Wait for Mermaid to load, then process diagrams
876+
function waitForMermaidAndProcess() {
877+
if (typeof mermaid !== 'undefined' && typeof window.processMermaidDiagrams === 'function') {
878+
// Wait a bit for Jekyll/Kramdown to finish processing
879+
setTimeout(() => {
859880
window.processMermaidDiagrams();
860-
}
861-
}, 300); // Increased delay for GitHub Pages
881+
}, 300);
882+
} else {
883+
// Mermaid not loaded yet, wait and try again
884+
setTimeout(waitForMermaidAndProcess, 100);
885+
}
862886
}
863887

864888
// Process diagrams when DOM is ready
865889
if (document.readyState === 'loading') {
866-
document.addEventListener('DOMContentLoaded', initMermaid);
890+
document.addEventListener('DOMContentLoaded', waitForMermaidAndProcess);
867891
} else {
868-
// DOM already loaded, process after a short delay
869-
initMermaid();
892+
// DOM already loaded, wait for Mermaid
893+
waitForMermaidAndProcess();
870894
}
871895
</script>
872-
873-
<!-- Fallback: Load Mermaid via regular script if module fails -->
874-
<script>
875-
// Check if mermaid was loaded after a delay
876-
setTimeout(() => {
877-
if (typeof window.mermaid === 'undefined') {
878-
console.log('Loading Mermaid via fallback script...');
879-
const script = document.createElement('script');
880-
script.src = 'https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.min.js';
881-
script.onload = function() {
882-
mermaid.initialize({
883-
startOnLoad: false,
884-
theme: 'default',
885-
securityLevel: 'loose',
886-
flowchart: { useMaxWidth: true },
887-
sequence: { useMaxWidth: true },
888-
gantt: { useMaxWidth: true }
889-
});
890-
window.mermaid = mermaid;
891-
892-
// Process diagrams after loading
893-
setTimeout(() => {
894-
if (typeof window.processMermaidDiagrams === 'function') {
895-
window.processMermaidDiagrams();
896-
} else {
897-
// Fallback processing
898-
const mermaidBlocks = document.querySelectorAll('code.language-mermaid, pre code.language-mermaid, code[class*="mermaid"]');
899-
mermaidBlocks.forEach((block) => {
900-
const preElement = block.parentElement;
901-
if (preElement && preElement.tagName === 'PRE') {
902-
const mermaidCode = block.textContent || block.innerText;
903-
const mermaidDiv = document.createElement('div');
904-
mermaidDiv.className = 'mermaid';
905-
mermaidDiv.textContent = mermaidCode;
906-
preElement.parentNode.replaceChild(mermaidDiv, preElement);
907-
}
908-
});
909-
mermaid.run();
910-
}
911-
}, 200);
912-
};
913-
document.head.appendChild(script);
914-
}
915-
}, 500);
916-
</script>
917896
</body>
918897

898+
</html>
919899
</html>

0 commit comments

Comments
 (0)