Skip to content

Commit

Permalink
Fix: mermaid diagrams with parameters in site config
Browse files Browse the repository at this point in the history
  • Loading branch information
deining committed Nov 23, 2022
1 parent b4d66f7 commit aa84320
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
9 changes: 1 addition & 8 deletions assets/js/mermaid.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
{{ $needmermaid := .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;

Expand All @@ -23,7 +17,7 @@
return;
}

var params = {{ . | jsonify | safeJS }};
var params = {{ .Site.Params.mermaid | jsonify | safeJS }};

// site params are stored with lowercase keys; lookup correct casing
// from Mermaid default config.
Expand All @@ -45,4 +39,3 @@
settings.startOnLoad = true;
mermaid.initialize(settings);
})(jQuery);
{{ end }}
17 changes: 12 additions & 5 deletions layouts/partials/scripts.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
{{ $needmermaid := .Site.Params.mermaid.enable -}}
{{ if ge hugo.Version "0.93.0" -}}
{{ with .Site.Params.mermaid }}
{{ $needmermaid = true }}
{{ end }}
{{ $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 -}}
<style>
.markmap > svg {
Expand Down Expand Up @@ -64,7 +63,15 @@
{{ if .Site.Params.offlineSearch -}}
{{ $jsSearch = resources.Get "js/offline-search.js" -}}
{{ end -}}
{{ $js := (slice $jsBs $jsBase $jsAnchor $jsSearch $jsMermaid $jsPlantuml $jsMarkmap $jsDrawio) | resources.Concat "js/main.js" -}}

{{ $jsArray := slice $jsBs $jsBase $jsAnchor $jsSearch $jsPlantuml $jsMarkmap $jsDrawio -}}

{{ if $needmermaid -}}
{{ $jsArray = $jsArray | append $jsMermaid -}}
<script src="https://cdn.jsdelivr.net/npm/mermaid@9.2.2/dist/mermaid.min.js" integrity="sha512-IX+bU+wShHqfqaMHLMrtwi4nK6W/Z+QdZoL4kPNtRxI2wCLyHPMAdl3a43Fv1Foqv4AP+aiW6hg1dcrTt3xc+Q==" crossorigin="anonymous"></script>
{{ end -}}

{{ $js := $jsArray | resources.Concat "js/main.js" -}}
{{ if hugo.IsProduction -}}
{{ $js := $js | minify | fingerprint -}}
<script src="{{ $js.RelPermalink }}" integrity="{{ $js.Data.Integrity }}" crossorigin="anonymous"></script>
Expand Down
4 changes: 4 additions & 0 deletions userguide/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ params:
disable_toc: false
markmap:
enable: true
mermaid:
theme: default
flowchart:
diagramPadding: 20

taxonomies:
tag: tags
Expand Down

0 comments on commit aa84320

Please sign in to comment.