Skip to content

Commit 1f848c0

Browse files
committed
Update post.js
1 parent d602a36 commit 1f848c0

1 file changed

Lines changed: 21 additions & 27 deletions

File tree

posts/js/post.js

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -98,39 +98,33 @@ fetch(`./posts/entries/${slug}.md`)
9898
footerDiv.textContent = `${author}, ${dateDisplay}${locationPart}`;
9999
content.appendChild(footerDiv);
100100

101-
// If MathJax is present, render any math
102-
if (window.MathJax) {
103-
window.MathJax.typesetPromise?.([content]).then(() => {
104-
if (window.mermaid) {
105-
try {
106-
mermaid.initialize({ startOnLoad: false });
107-
const mermaidBlocks = bodyDiv.querySelectorAll('.mermaid');
108-
if (mermaidBlocks.length > 0) {
109-
mermaid.init(undefined, mermaidBlocks);
110-
}
111-
} catch (e) {
112-
console.warn("Mermaid failed to render:", e);
113-
}
114-
}
115-
}).catch((e) => {
116-
console.warn("MathJax error, attempting Mermaid anyway:", e);
117-
if (window.mermaid) {
118-
mermaid.initialize({ startOnLoad: false });
119-
const mermaidBlocks = bodyDiv.querySelectorAll('.mermaid');
120-
if (mermaidBlocks.length > 0) {
121-
mermaid.init(undefined, mermaidBlocks);
122-
}
123-
}
124-
});
125-
} else {
126-
if (window.mermaid) {
101+
function renderMermaid() {
102+
if (!window.mermaid) return;
103+
try {
127104
mermaid.initialize({ startOnLoad: false });
128105
const mermaidBlocks = bodyDiv.querySelectorAll('.mermaid');
129106
if (mermaidBlocks.length > 0) {
130-
mermaid.init(undefined, mermaidBlocks);
107+
if (typeof mermaid.run === 'function') {
108+
mermaid.run({ nodes: mermaidBlocks });
109+
} else if (typeof mermaid.init === 'function') {
110+
mermaid.init(undefined, mermaidBlocks);
111+
}
131112
}
113+
} catch (e) {
114+
console.warn('Mermaid failed to render:', e);
132115
}
133116
}
117+
118+
if (window.MathJax) {
119+
window.MathJax.typesetPromise?.([content])
120+
.then(renderMermaid)
121+
.catch(e => {
122+
console.warn('MathJax error, attempting Mermaid anyway:', e);
123+
renderMermaid();
124+
});
125+
} else {
126+
renderMermaid();
127+
}
134128
})
135129
.catch(e => {
136130
console.error(e);

0 commit comments

Comments
 (0)