I found 4 tutorials that all embed Mermaid differently:
This says: Add Diagrams to your Jekyll/Hugo/Gatsby blog with Mermaid JS · Code with Hugo
Add this code to layouts/shortcodes/mermaid.html
:
<div class="mermaid">
{{.Inner}}
</div>
and add this to unknown location:
{{ if (.Params.mermaid) }}
<!-- MermaidJS support -->
<script async src="https://unpkg.com/mermaid@8.2.3/dist/mermaid.min.js"></script>
{{ end }}
This says: On The Other Hand · Integrating Mermaid JS Into Hugo
Add to layouts/shortcodes/mermaid.html
:
{{ if ($.Page.Params.mermaid) }}
<script src="//cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"></script>
<script>!window.mermaid && document.write(unescape('%3Cscript src="/js/mermaid-8.9.1/mermaid.min.js"%3E%3C/script%3E'))</script>
<script>mermaid.initialize({startOnLoad:true});</script>
{{ end }}
<div class="mermaid">
{{.Inner}}
</div>
This says: skeptric - Diagrams in Hugo with Mermaid
Add to layouts/shortcodes/mermaid.html
{{ $_hugo_config := `{ "version": 1 }` }}
<div class="mermaid" align="{{ if .Get "align" }}{{ .Get "align" }}{{ else }}center{{ end }}">{{ safeHTML .Inner }}</div>
and in layouts/partials/site-header.html
:
<script src="https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"></script>
<script>mermaid.initialize({ startOnLoad: true, securityLevel: 'loose'}});</script>
And this says: Build and display Mermaid.js diagrams in Hugo
Add to layouts/shortcodes/mermaid.html
:
<script async type="application/javascript" src="https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js">
var config = {
startOnLoad:true,
theme:'{{ if .Get "theme" }}{{ .Get "theme" }}{{ else }}dark{{ end }}',
align:'{{ if .Get "align" }}{{ .Get "align" }}{{ else }}center{{ end }}'
};
mermaid.initialize(config);
</script>
<div class="mermaid">
{{.Inner}}
</div>
What is the RIGHT way?