Skip to content

Commit 0ffc029

Browse files
committed
Removed compatibility with hugo versions <v0.110.0
Updated user guide
1 parent cf57fbf commit 0ffc029

File tree

4 files changed

+50
-78
lines changed

4 files changed

+50
-78
lines changed

layouts/partials/scripts.html

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
{{ $needKaTeX := or .Site.Params.katex.enable .Params.math .Params.chem -}}
22
{{ $needmhchem := or .Site.Params.katex.mhchem.enable .Params.chem -}}
3-
{{ $needmermaid := .Site.Params.mermaid.enable -}}
43
{{ if ge hugo.Version "0.93.0" -}}
5-
{{ with .Site.Params.mermaid }}
6-
{{ $needmermaid = true }}
7-
{{ end }}
84
{{ $needKaTeX = or $needKaTeX (.Page.Store.Get "hasKaTeX") (.Page.Store.Get "hasmhchem") -}}
95
{{ $needmhchem = or $needmhchem (.Page.Store.Get "hasmhchem") -}}
10-
{{ $needmermaid = or $needmermaid (.Page.Store.Get "hasmermaid") -}}
116
{{ else -}}
12-
{{ if or $needKaTeX $needmhchem $needmermaid -}}
7+
{{ if or $needKaTeX $needmhchem -}}
138
{{ warnf "Outdated Hugo version %s, consider upgrading to make full use of all theme features" hugo.Version }}
149
{{ end -}}
1510
{{ end -}}
@@ -75,8 +70,8 @@
7570

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

78-
{{ if $needmermaid -}}
79-
{{ partial "scripts/mermaid.html" . -}}
73+
{{ if .Page.Store.Get "hasmermaid" -}}
74+
{{- partial "scripts/mermaid.html" . -}}
8075
{{ end -}}
8176

8277
{{ $js := $jsArray | resources.Concat "js/main.js" -}}

layouts/partials/scripts/mermaid.html

+14-26
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,22 @@
1-
{{ $version := cond ( ge hugo.Version "0.90.0" ) "latest" "10.6.1" -}}
1+
{{ $version := "latest" -}}
22
{{ with .Site.Params.mermaid.version -}}
33
{{ $version = . -}}
44
{{ end -}}
55

66
{{ $cdnurl := printf "https://cdn.jsdelivr.net/npm/mermaid@%s/dist/mermaid.esm.min.mjs" $version -}}
7-
{{ if ge hugo.Version "0.90.0" -}}
8-
{{ if eq (resources.GetRemote $cdnurl) nil -}}
9-
{{ errorf "Invalid Mermaid version %s, could not retrieve this version from CDN" $version -}}
10-
{{ end -}}
11-
{{ else -}}
12-
{{ warnf "Outdated Hugo version %s, consider upgrading to make full use of all theme features" hugo.Version -}}
13-
{{ end -}}
7+
{{ with resources.GetRemote $cdnurl }}
8+
{{ with .Err }}
9+
{{ errorf "Could not retrieve mermaid script from CDN. Reason: %s." . }}
10+
{{ end }}
11+
{{ else }}
12+
{{ errorf "Invalid Mermaid version %s, could not retrieve this version from CDN." $version }}
13+
{{ end }}
1414

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

1818
(function($) {
19-
var needMermaid = false;
20-
21-
{{ if ge hugo.Version "0.93.0" -}}
22-
if ($('.mermaid').length > 0) {
23-
needMermaid = true;
24-
};
25-
{{ else -}}
26-
$('.language-mermaid').parent().replaceWith(function() {
27-
needMermaid = true;
28-
return $('<pre class="mermaid">').text($(this).text());
29-
});
30-
{{ end -}}
31-
32-
if (!needMermaid) {
19+
if ($('.mermaid').length == 0) {
3320
mermaid.initialize({startOnLoad: false});
3421
return;
3522
}
@@ -52,9 +39,10 @@
5239
}
5340
return result;
5441
};
55-
//var settings = norm(mermaid.mermaidAPI.defaultConfig, params);
56-
//settings.startOnLoad = true;
57-
mermaid.initialize(params);
42+
43+
var settings = norm(mermaid.mermaidAPI.defaultConfig, params);
44+
settings.startOnLoad = true;
45+
mermaid.initialize(settings);
5846
})(jQuery);
5947

60-
</script>
48+
</script>

userguide/content/en/docs/adding-content/diagrams-and-formulae/index.md

+33-42
Original file line numberDiff line numberDiff line change
@@ -342,58 +342,49 @@ With Mermaid support enabled in Docsy, you can include the text definition of a
342342

343343
The great advantage of this is anyone who can edit the page can now edit the diagram - no more hunting for the original tools and version to make a new edit.
344344

345-
For example, the following defines a simple flowchart:
345+
For example, the following defines a sequence diagram:
346346

347347
````
348348
```mermaid
349-
graph TD
350-
Start --> Need{"Hugo version >= 0.93.0"}
351-
Need -- No --> Off["Set params.mermaid.enable = true"]
352-
Off --> Author
353-
Need -- Yes --> Author[Insert mermaid codeblock]
354-
```
349+
sequenceDiagram
350+
autonumber
351+
Docsy user->>Discussion board: Ask question
352+
Discussion board->>Community member: read question
353+
loop Different strategies
354+
Community member->>Test instance: Investigate issue raised
355+
end
356+
Note right of Community member: After hours of investigation:
357+
Test instance-->>Community member: Come up with solution
358+
Community member-->>Discussion board: Propose solution
359+
Discussion board-->>Docsy user: check proposed solution
360+
Docsy user->>Discussion board: Mark question as resolved
361+
Docsy user->>Docsy user: Being happy```
355362
````
356363

357-
Automatically renders to:
364+
which is automatically rendered to:
358365

359366
```mermaid
360-
graph TD
361-
Start --> Need{"Hugo version >= 0.93.0"}
362-
Need -- No --> Off["Set params.mermaid.enable = true"]
363-
Off --> Author
364-
Need -- Yes --> Author[Insert mermaid codeblock]
367+
sequenceDiagram
368+
autonumber
369+
Docsy user->>Discussion board: Ask question
370+
Discussion board->>Community member: read question
371+
loop Different strategies
372+
Community member->>Test instance: Investigate issue raised
373+
end
374+
Note right of Community member: After hours of investigation:
375+
Test instance-->>Community member: Come up with solution
376+
Community member-->>Discussion board: Propose solution
377+
Discussion board-->>Docsy user: check proposed solution
378+
Docsy user->>Discussion board: Mark question as resolved
379+
Docsy user->>Docsy user: Being happy
365380
```
366381

367-
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.
382+
Support of Mermaid diagrams is automatically enabled as soon as you use a `mermaid` code block on your page.
368383

369-
In case of hugo version 0.92 or lower you have to enable mermaid manually inside your `hugo.toml`/`hugo.yaml`/`hugo.json`:
370-
371-
{{< tabpane >}}
372-
{{< tab header="Hugo version <= 0.92 only:" disabled=true />}}
373-
{{< tab header="hugo.toml" lang="toml" >}}
374-
[params.mermaid]
375-
enable = true
376-
{{< /tab >}}
377-
{{< tab header="hugo.yaml" lang="yaml" >}}
378-
params:
379-
mermaid:
380-
enable: true
381-
{{< /tab >}}
382-
{{< tab header="hugo.json" lang="json" >}}
383-
{
384-
"params": {
385-
"mermaid": {
386-
"enable": true
387-
}
388-
}
389-
}
390-
{{< /tab >}}
391-
{{< /tabpane >}}
392-
393-
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`:
384+
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 configuration file `hugo.toml`/`hugo.yaml`/`hugo.json`:
394385

395386
{{< tabpane persistLang=false >}}
396-
{{< tab header="Hugo version >= 0.90 only:" disabled=true />}}
387+
{{< tab header="Configuration file:" disabled=true />}}
397388
{{< tab header="hugo.toml" lang="toml" >}}
398389
[params.mermaid]
399390
version = "10.6.1"
@@ -446,9 +437,9 @@ params:
446437
{{< /tab >}}
447438
{{< /tabpane >}}
448439

449-
See the [Mermaid documentation](https://mermaid-js.github.io/mermaid/#/Setup?id=mermaidapi-configuration-defaults) for a list of defaults that can be overridden.
440+
See the [Mermaid source code](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/defaultConfig.ts#L18) for a list of defaults that can be overridden.
450441

451-
Settings can also be overridden on a per-diagram basis by making use of the `%%init%%` header at the start of the diagram definition. See the [Mermaid theming documentation](https://mermaid-js.github.io/mermaid/#/theming?id=themes-at-the-local-or-current-level).
442+
Settings can also be overridden on a per-diagram basis by making use of a [frontmatter config](http://mermaid.js.org/config/theming.html#customizing-themes-with-themevariables) block at the start of the diagram definition.
452443

453444
## UML Diagrams with PlantUML
454445

userguide/hugo.yaml

-2
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,6 @@ params:
119119
disable_toc: false
120120
markmap:
121121
enable: true
122-
mermaid:
123-
version: 10.6.1
124122
drawio:
125123
enable: true
126124

0 commit comments

Comments
 (0)