Skip to content

Commit

Permalink
Bump to mermaid 10.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
deining committed Mar 13, 2023
1 parent 8e764f3 commit cbc57f9
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 65 deletions.
41 changes: 0 additions & 41 deletions assets/js/mermaid.js

This file was deleted.

2 changes: 0 additions & 2 deletions layouts/partials/scripts.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
{{ $jsBase := resources.Get "js/base.js" -}}
{{ $jsAnchor := resources.Get "js/anchor.js" -}}
{{ $jsSearch := resources.Get "js/search.js" | resources.ExecuteAsTemplate "js/search.js" .Site.Home -}}
{{ $jsMermaid := resources.Get "js/mermaid.js" | resources.ExecuteAsTemplate "js/mermaid.js" . -}}
{{ $jsMarkmap := resources.Get "js/markmap.js" | resources.ExecuteAsTemplate "js/markmap.js" . -}}
{{ $jsPlantuml := resources.Get "js/plantuml.js" | resources.ExecuteAsTemplate "js/plantuml.js" . -}}
{{ $jsDrawio := resources.Get "js/drawio.js" | resources.ExecuteAsTemplate "js/drawio.js" . -}}
Expand All @@ -77,7 +76,6 @@
{{ $jsArray := slice $jsBs $jsBase $jsAnchor $jsSearch $jsPlantuml $jsMarkmap $jsDrawio -}}

{{ if $needmermaid -}}
{{ $jsArray = $jsArray | append $jsMermaid -}}
{{ partial "scripts/mermaid.html" . -}}
{{ end -}}

Expand Down
61 changes: 51 additions & 10 deletions layouts/partials/scripts/mermaid.html
Original file line number Diff line number Diff line change
@@ -1,19 +1,60 @@
{{ $version := cond ( ge hugo.Version "0.90.0" ) "latest" "9.3.0" -}}
{{ $version := cond ( ge hugo.Version "0.90.0" ) "latest" "10.0.2" -}}
{{ with .Site.Params.mermaid.version -}}
{{ $version = . -}}
{{ end -}}

{{ $cdnurl := printf "https://cdn.jsdelivr.net/npm/mermaid@%s/dist/mermaid.min.js" $version -}}
{{ $cdnurl := printf "https://cdn.jsdelivr.net/npm/mermaid@%s/dist/mermaid.esm.min.mjs" $version -}}
{{ if ge hugo.Version "0.90.0" -}}
{{ $mermaidjs := resources.GetRemote $cdnurl -}}
{{ if eq $mermaidjs nil -}}
{{ if eq (resources.GetRemote $cdnurl) nil -}}
{{ errorf "Invalid Mermaid version %s, could not retrieve this version from CDN" $version -}}
{{ end -}}
{{ else -}}
{{ $mermaidsecure := $mermaidjs | resources.Fingerprint "sha512" -}}
<script type="text/javascript" src="{{ $mermaidsecure.Permalink }}" integrity="{{ $mermaidsecure.Data.Integrity -}}">
</script>
{{ end }}
{{ else -}}
<script src="{{- $cdnurl -}}" integrity="sha512-ku2nmBrzAXY5YwohzTqLYH1/lvyMrpTVxgQKrvTabd/b/uesqltLORdmpVapYv6QhZVCLUX6wkvFaKOAY4xpUA==" crossorigin="anonymous"></script>
{{ warnf "Outdated Hugo version %s, consider upgrading to make full use of all theme features" hugo.Version -}}
{{ end -}}

<script type="module" async>
import mermaid from "{{- $cdnurl -}}";

(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});
return;
}

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

// site params are stored with lowercase keys; lookup correct casing
// from Mermaid default config.
var norm = function(defaultConfig, params) {
var result = {};
for (const key in defaultConfig) {
const keyLower = key.toLowerCase();
if (defaultConfig.hasOwnProperty(key) && params.hasOwnProperty(keyLower)) {
if (typeof defaultConfig[key] === "object") {
result[key] = norm(defaultConfig[key], params[keyLower]);
} else {
result[key] = params[keyLower];
}
}
}
return result;
};
//var settings = norm(mermaid.mermaidAPI.defaultConfig, params);
//settings.startOnLoad = true;
mermaid.initialize(params);
})(jQuery);

</script>
Original file line number Diff line number Diff line change
Expand Up @@ -367,47 +367,48 @@ graph TD

With hugo version 0.93 or higher, support of Mermaid diagrams is automatically enabled as soon as you use a `mermaid` code block on your page.

By default, docsy pulls in the latest officially released version of Mermaid at build time. If that doesn't fit your needs, you can specify the wanted mermaid version inside your `hugo.toml`:
In case of hugo version 0.92 or lower you have to enable mermaid manually inside your `hugo.toml`/`hugo.yaml`/`hugo.json`:

{{< tabpane persistLang=false >}}
{{< tab header="Hugo version >= 0.90 only:" disabled=true />}}
{{< tab header="Hugo version <= 0.92 only:" disabled=true />}}
{{< tab header="hugo.toml" lang="toml" >}}
[params.mermaid]
version = "9.3.0"
enable = true
{{< /tab >}}
{{< tab header="hugo.yaml" lang="yaml" >}}
params:
mermaid:
version: 9.3.0
enable: true
{{< /tab >}}
{{< tab header="hugo.json" lang="json" >}}
{
"params": {
"mermaid": {
"version": "9.3.0"
"enable": true
}
}
}
{{< /tab >}}
{{< /tabpane >}}

By default, docsy pulls in the latest officially released version of Mermaid at build time. If that doesn't fit your needs, you can specify the wanted mermaid version inside your `hugo.toml`:

{{< tabpane persistLang=false >}}
{{< tab header="Hugo version <= 0.92 only:" disabled=true />}}
{{< tab header="Hugo version >= 0.90 only:" disabled=true />}}
{{< tab header="hugo.toml" lang="toml" >}}
[params.mermaid]
enable = true
version = "10.0.2"
{{< /tab >}}
{{< tab header="hugo.yaml" lang="yaml" >}}
params:
mermaid:
enable: true
version: 10.0.2
{{< /tab >}}
{{< tab header="hugo.json" lang="json" >}}
{
"params": {
"mermaid": {
"enable": true
"version": "10.0.2"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Hugo's commands for module management require that the Go programming language i
```console
$ go version
go version go1.19.2 windows/amd64
go version go1.20.2 windows/amd64
```
Ensure that you are using version 1.12 or higher.
Expand All @@ -84,7 +84,7 @@ Hugo's commands for module management require that the `git` client is installed

```console
$ git version
git version 2.39.1
git version 2.40.0
```

If no `git` client is installed on your system yet, go to the [Git website](https://git-scm.com/), download the installer for your system architecture and execute it. Afterwards, check for a successful installation.
Expand Down
2 changes: 1 addition & 1 deletion userguide/hugo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ params:
markmap:
enable: true
mermaid:
version: 9.3.0
version: 10.0.2
theme: default
flowchart:
diagramPadding: 20
Expand Down

0 comments on commit cbc57f9

Please sign in to comment.