Skip to content

Commit 902d1bf

Browse files
timvw74lxndrblz
andauthored
feat: update Mermaid diagrams to follow theme preference (#576)
* [Issue 575] Update Mermaid Diagrams to follow theme * [Issue 575] Add example post * chore: downgrade Node.js version * chore: install lighthouse plugin with npm --------- Co-authored-by: Alexander Bilz <[email protected]>
1 parent 11aa6c0 commit 902d1bf

File tree

5 files changed

+2626
-57
lines changed

5 files changed

+2626
-57
lines changed

exampleSite/config/_default/hugo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ pygmentsCodefencesGuessSyntax = true
2222
# Localized dates requires Hugo version 0.87.0
2323
localizedDates = false
2424

25+
# Mermaid
26+
[params.mermaid]
27+
enable = true
28+
2529
[markup]
2630
[markup.goldmark]
2731
[markup.goldmark.renderer]
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
+++
2+
author = "Hugo Authors"
3+
title = "Guide to Mermaid Diagrams in Hugo"
4+
date = "2025-08-11"
5+
description = "Guide to Mermaid Diagrams in Hugo"
6+
tags = [
7+
"thumbnail",
8+
]
9+
thumbnail= "images/landscape.jpg"
10+
+++
11+
12+
For displaying diagrams and charts in a Hugo project, you can leverage Mermaid.
13+
14+
If you want to use Mermaid diagrams in your site, enable mermaid support in your config file:
15+
16+
17+
```toml
18+
[params.mermaid]
19+
enable = true
20+
```
21+
22+
You can then use mermaid syntax to display your diagram:
23+
24+
```markdown
25+
```mermaid
26+
sequenceDiagram
27+
Alice ->> Bob: Hello Bob, how are you?
28+
Bob-->>John: How about you John?
29+
Bob--x Alice: I am good thanks!
30+
Bob-x John: I am good thanks!
31+
Note right of John: Bob thinks a long<br/>long time, so long<br/>that the text does<br/>not fit on a row.
32+
33+
Bob-->Alice: Checking with John...
34+
Alice->John: Yes... John, how are you?
35+
```
36+
```
37+
38+
39+
Which should render your diagram as:
40+
41+
42+
43+
```mermaid
44+
sequenceDiagram
45+
Alice ->> Bob: Hello Bob, how are you?
46+
Bob-->>John: How about you John?
47+
Bob--x Alice: I am good thanks!
48+
Bob-x John: I am good thanks!
49+
Note right of John: Bob thinks a long<br/>long time, so long<br/>that the text does<br/>not fit on a row.
50+
51+
Bob-->Alice: Checking with John...
52+
Alice->John: Yes... John, how are you?
53+
```

layouts/partials/mermaid.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{{ if .Page.Store.Get "hasMermaid" }}
22
<script src="https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"></script>
33
<script>
4-
mermaid.initialize({ startOnLoad: true });
4+
const mermaidtheme = getStoredThemeStyle() === 'dark' ? 'dark' : 'base';
5+
mermaid.initialize({ startOnLoad: true, theme: mermaidtheme });
56
</script>
67
{{ end }}

0 commit comments

Comments
 (0)