Skip to content

Commit 63ae0c7

Browse files
committed
Merge branch 'main' of github.com:rot1024/astrotion
2 parents c53d82d + 665a5e9 commit 63ae0c7

File tree

5 files changed

+64
-73
lines changed

5 files changed

+64
-73
lines changed

package-lock.json

Lines changed: 4 additions & 72 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"ezog": "^0.4.0",
3333
"katex": "^0.16.25",
3434
"mermaid": "^11.12.1",
35-
"notiondown": "^0.3.0",
35+
"notiondown": "^0.3.1",
3636
"sharp": "^0.34.4",
3737
"tailwindcss": "^4.1.16"
3838
},

src/pages/posts/[slug].astro

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ const { database, post, html } = await getPost(slug);
5656
</article>
5757
</main>
5858
</Layout>
59+
<script>
60+
import "../../scripts/mermaid";
61+
</script>
5962
<style
6063
define:vars={{
6164
titleFontFamily: config.index?.titleFontFamily || "inherit",

src/scripts/mermaid.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import mermaid from "mermaid";
2+
3+
// Initialize mermaid with default configuration
4+
mermaid.initialize({
5+
startOnLoad: false,
6+
theme: "default",
7+
securityLevel: "loose",
8+
});
9+
10+
// Wait for DOM to be ready
11+
if (document.readyState === "loading") {
12+
document.addEventListener("DOMContentLoaded", initMermaid);
13+
} else {
14+
initMermaid();
15+
}
16+
17+
function initMermaid() {
18+
// Find all code blocks with language-mermaid class
19+
const mermaidBlocks = document.querySelectorAll<HTMLElement>(
20+
"pre code.language-mermaid, pre.language-mermaid code",
21+
);
22+
23+
if (mermaidBlocks.length === 0) {
24+
return;
25+
}
26+
27+
mermaidBlocks.forEach((block, index) => {
28+
const code = block.textContent || "";
29+
const pre = block.closest("pre");
30+
31+
if (pre && code.trim()) {
32+
// Create a new div to hold the mermaid diagram
33+
const div = document.createElement("div");
34+
div.className = "mermaid";
35+
div.textContent = code.trim();
36+
div.id = `mermaid-diagram-${index}`;
37+
38+
// Replace the pre element with the mermaid div
39+
pre.replaceWith(div);
40+
}
41+
});
42+
43+
// Trigger mermaid rendering
44+
mermaid.run({
45+
querySelector: ".mermaid",
46+
});
47+
}

src/styles/markdown.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,12 @@
125125
.markdown .youtube {
126126
@apply aspect-video w-full h-auto;
127127
}
128+
129+
.markdown .mermaid {
130+
@apply my-8 flex justify-center;
131+
}
132+
133+
.markdown .mermaid svg {
134+
max-width: 100%;
135+
height: auto;
136+
}

0 commit comments

Comments
 (0)