Skip to content

Commit e471a02

Browse files
committed
fix: Add fallback Mermaid loading for GitHub Pages compatibility
- Added fallback script loader if ES module fails - Increased delay to 300ms for GitHub Pages processing - Made mermaid available globally for fallback - Ensures diagrams render even if module loading fails
1 parent a305737 commit e471a02

1 file changed

Lines changed: 44 additions & 1 deletion

File tree

docs_site/_layouts/default.html

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,7 @@
851851
// Wait a bit for Jekyll/Kramdown to finish processing
852852
setTimeout(() => {
853853
processMermaidDiagrams();
854-
}, 100);
854+
}, 300); // Increased delay for GitHub Pages
855855
}
856856

857857
// Process diagrams when DOM is ready
@@ -862,6 +862,49 @@
862862
initMermaid();
863863
}
864864
</script>
865+
866+
<!-- Fallback: Load Mermaid via regular script if module fails -->
867+
<script>
868+
// If mermaid wasn't loaded via module, load it via regular script
869+
if (typeof window.mermaid === 'undefined') {
870+
console.log('Loading Mermaid via fallback script...');
871+
const script = document.createElement('script');
872+
script.src = 'https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.min.js';
873+
script.onload = function() {
874+
mermaid.initialize({
875+
startOnLoad: false,
876+
theme: 'default',
877+
securityLevel: 'loose',
878+
flowchart: { useMaxWidth: true },
879+
sequence: { useMaxWidth: true },
880+
gantt: { useMaxWidth: true }
881+
});
882+
window.mermaid = mermaid;
883+
884+
// Process diagrams after loading
885+
setTimeout(() => {
886+
if (typeof processMermaidDiagrams === 'function') {
887+
processMermaidDiagrams();
888+
} else {
889+
// Fallback processing
890+
const mermaidBlocks = document.querySelectorAll('code.language-mermaid, pre code.language-mermaid, code[class*="mermaid"]');
891+
mermaidBlocks.forEach((block) => {
892+
const preElement = block.parentElement;
893+
if (preElement && preElement.tagName === 'PRE') {
894+
const mermaidCode = block.textContent || block.innerText;
895+
const mermaidDiv = document.createElement('div');
896+
mermaidDiv.className = 'mermaid';
897+
mermaidDiv.textContent = mermaidCode;
898+
preElement.parentNode.replaceChild(mermaidDiv, preElement);
899+
}
900+
});
901+
mermaid.run();
902+
}
903+
}, 100);
904+
};
905+
document.head.appendChild(script);
906+
}
907+
</script>
865908
</body>
866909

867910
</html>

0 commit comments

Comments
 (0)