Adding Mermaid Diagrams to Your Zola Blog
How to add Mermaid diagram rendering to a Zola static blog.
The Approach
Mermaid renders diagrams client-side in the browser — no backend required. The architecture:
Markdown → Zola build → Static HTML → Browser loads Mermaid.js → Renders diagrams
The core idea: load Mermaid.js on the page and have it automatically render language-mermaid code blocks.
Setup Steps
Step 1: Create the Mermaid Script
Create static/js/mermaid.js:
'DOMContentLoaded', ;
Step 2: Load the Script in the Template
Add a script tag in templates/base.html before </body> to load mermaid.js, using Zola’s get_url function to generate the correct path.
See templates/base.html in this project for the actual implementation.
Step 3: Add Styles
Add Mermaid container styles to static/sass/main.scss:
{
:;
:;
:;
:;
:;
:;
:;
{
:;
:;
}
}
Usage
Use fenced mermaid code blocks in Markdown:
graph TD
A[Start] --> B{Condition}
B -->|Yes| C[Run A]
B -->|No| D[Run B]
C --> E[End]
D --> E
Key File Reference
| File | Path |
|---|---|
| Mermaid script | static/js/mermaid.js |
| Template | templates/base.html |
| Stylesheet | static/sass/main.scss |
| Example post | content/posts/mermaid 流程图使用指南.md |
References
| Resource | Link |
|---|---|
| Mermaid docs | mermaid.js.org |
| Live editor | mermaid.live |
| Zola static files | getzola.org |
| Zola templates | getzola.org |
Notes
- Mermaid loads from CDN — requires internet access
- For offline use, download
mermaid.min.jstostatic/js/ - Supports flowcharts, sequence diagrams, class diagrams, state diagrams, pie charts, Gantt charts, and more
Comments