Hugo and Mermaid Integration
Introduction
By default Hugo is not supporting Mermaid integration. But there is a way to make it work.
Mermaid Javascript
Get the mermaid Javascript to transform the graphic description into a graphic:
https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js
Get the file and copy in folder /static/js.
Partial for Mermaid usage in Markdown
In folder layouts/_default/_markup
create a new file render-codeblock-mermaid.html
and paste the following content :
|
|
Update Content Page
In the baseof.html
file at the bottom, add the code below (in my case after the {{ partial "footer.html" . }}
):
|
|
Sample
Class Diagram
The Class Diagram below is created using the code below in a markdown file:
```mermaid
---
title: Mermaid Class Diagram Example
---
classDiagram
note "This is a general note"
Item <|-- Box
note for Box "can never be empty"
Item <|-- Can
Item <|-- Glass
Item : +String Material
Item : +String Name
Item: +isComposed()
Item: +isRenewable()
class Can{
+String Color
+Fill()
+Open()
}
class Glass{
+Fill()
}
class Box{
+String Material
+Item[]
+Fill()
+Close()
+Open()
+Deliver()
}
---
title: Mermaid Class Diagram Example
---
classDiagram
note "This is a general note"
Item <|-- Box
note for Box "can never be empty"
Item <|-- Can
Item <|-- Glass
Item : +String Material
Item : +String Name
Item: +isComposed()
Item: +isRenewable()
class Can{
+String Color
+Fill()
+Open()
}
class Glass{
+Fill()
}
class Box{
+String Material
+Item[]
+Fill()
+Close()
+Open()
+Deliver()
}
Workflow
flowchart TD
start((Scheduler))
starttb((Scheduler))
ready(((Web)))
start-.2am.->extract
starttb-.7am.->prepare
mdFiles==>split
expose-->ready
subgraph extract[Jenkins fa:fa-cogs]
cpi-->cpiconfig
end
subgraph prepare[CPIToolbox fa:fa-cogs]
cpiconfig-->cpicfgextract-->mdFiles
btsconfig-->btscfgextract-->mdFiles
mftconfig-->mftcfgextract-->mdFiles
pwcconfig-->pwccfgextract-->mdFiles
mdFiles[Markdown fa:fa-file]
end
subgraph present[Hugo fa:fa-cog]
split-->dev
split-->test
split-->preprod
split-->prod
split{Split}
dev[DEV fa:fa-file-code]
test[TEST fa:fa-file-code]
preprod[PrePROD fa:fa-file-code]
prod[PROD fa:fa-file-code]
end
subgraph expose[NGinx fa:fa-globe]
dev-->html
test-->html
preprod-->html
prod-->html
end
cpi[[CPI Config Extract]]
cpicfgextract[[CpiConfigExtractor]]
btscfgextract[[BtsConfigExtractor]]
mftcfgextract[[MftConfigExtractor]]
pwccfgextract[[PwcConfigExtractor]]
cpiconfig[cfg files fa:fa-file]
btsconfig[(DB Mgmt fa:fa-file)]
mftconfig[Files fa:fa-file]
pwcconfig[(DB cfg fa:fa-file)]