Skip to content

Commit

Permalink
mermaid diagrams: automatic activation (with hugo >=0.93.0)
Browse files Browse the repository at this point in the history
  • Loading branch information
deining committed Oct 21, 2022
1 parent b3ac2d3 commit 8107dab
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
17 changes: 14 additions & 3 deletions assets/js/mermaid.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
{{ with .Site.Params.mermaid }}
{{ if .enable }}
{{ $needmermaid := or .Site.Params.mermaid.enable -}}
{{ if ge hugo.Version "0.93.0" -}}
{{ $needmermaid = or $needmermaid (.Page.Store.Get "hasmermaid") -}}
{{ end }}

{{ if $needmermaid }}
(function($) {
var needMermaid = false;

{{ if ge hugo.Version "0.93.0" -}}
if ($('.mermaid').length > 0) {
needMermaid = true;
};
{{ else -}}
$('.language-mermaid').parent().replaceWith(function() {
needMermaid = true;
return $('<pre class="mermaid">').text($(this).text());
});
{{ end -}}

if (!needMermaid) {
mermaid.initialize({startOnLoad: false});
Expand Down Expand Up @@ -34,4 +46,3 @@
mermaid.initialize(settings);
})(jQuery);
{{ end }}
{{ end }}
2 changes: 2 additions & 0 deletions layouts/_default/_markup/render-codeblock-mermaid.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{{ .Page.Store.Set "hasmermaid" true -}}

<div class="mermaid">
{{- .Inner | safeHTML }}
</div>
9 changes: 7 additions & 2 deletions layouts/partials/scripts.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{{ if .Site.Params.mermaid.enable -}}
<script src="https://cdn.jsdelivr.net/npm/mermaid@9.1.3/dist/mermaid.min.js" integrity="sha512-E/owfVh8/U1xwhvIT4HSI064DRc1Eo/xf7AYax84rt9gVqA8tc/JNH/lvTl1tuw9PUHQIMGUtObkjYkgRjFqAA==" crossorigin="anonymous"></script>
{{ $needmermaid := or .Site.Params.mermaid.enable -}}
{{ if ge hugo.Version "0.93.0" -}}
{{ $needmermaid = or $needmermaid (.Page.Store.Get "hasmermaid") -}}
{{ end }}

{{ if $needmermaid -}}
<script src="https://cdn.jsdelivr.net/npm/mermaid@9.1.7/dist/mermaid.min.js" integrity="sha512-1ypa9tdUrJAWv5g28Mb5x0zXaUuI4SBofKff88OGyk5D/oOd4x1IPxYHsx3K81bwBKt8NVUvGgw7TgNZ6PJX2A==" crossorigin="anonymous"></script>
{{ end -}}

{{ if .Site.Params.markmap.enable -}}
Expand Down
3 changes: 0 additions & 3 deletions userguide/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,6 @@ params:
icon: fa-brands fa-github
desc: Development takes place here!

mermaid:
enable: true
theme: default
plantuml:
enable: true
theme: default
Expand Down

0 comments on commit 8107dab

Please sign in to comment.