perf: optimize mermaid script loading

This commit is contained in:
Henk Verlinde 2021-07-02 11:08:31 +02:00
parent 6e00bc86da
commit 701a4b81d1
4 changed files with 5 additions and 11 deletions

View File

@ -72,4 +72,3 @@ editPage = false
highLight = true
kaTex = false
collapsibleSidebar = false
mermaid = true

View File

@ -11,14 +11,9 @@ menu:
parent: "prologue"
weight: 110
toc: true
mermaid: true
---
```js
function myFunction(p1, p2) {
return p1 * p2; // The function returns the product of p1 and p2
}
```
## Flowchart
### Shortcode

View File

@ -65,7 +65,7 @@
<script src="{{ $katexAutoRender.RelPermalink }}" onload="renderMathInElement(document.body);" defer></script>
{{ end -}}
<script src="{{ $js.RelPermalink }}" defer></script>
{{ if .Site.Params.options.mermaid -}}
{{ with .Params.mermaid -}}
<script src="{{ $mermaid.RelPermalink }}" defer></script>
{{ end -}}
{{ if .Site.Params.options.flexSearch -}}
@ -90,7 +90,7 @@
<script src="{{ $katexAutoRender.RelPermalink }}" integrity="{{ $katexAutoRender.Data.Integrity }}" crossorigin="anonymous" defer></script>
{{ end -}}
<script src="{{ $js.RelPermalink }}" integrity="{{ $js.Data.Integrity }}" crossorigin="anonymous" defer></script>
{{ if .Site.Params.options.mermaid -}}
{{ with .Params.mermaid -}}
<script src="{{ $mermaid.RelPermalink }}" integrity="{{ $mermaid.Data.Integrity }}" crossorigin="anonymous" defer></script>
{{ end -}}
{{ if .Site.Params.options.flexSearch -}}

View File

@ -1,8 +1,8 @@
{{ if .Site.Params.options.mermaid -}}
{{ if .Page.Params.mermaid -}}
<div class="mermaid{{ with .Get "class" }} {{ . }}{{ end }}">
{{ $data := replaceRE "(^\\s+```)" "" .Inner -}}
{{ replaceRE "(```\\s+$)" "" $data -}}
</div>
{{ else -}}
{{ errorf "Failed to process mermaid shortcode(s). Set `mermaid = true` in `./config/_default/params.toml`." }}
{{ errorf "Failed to process mermaid shortcode: %s. Set mermaid to true in page front matter." .Position }}
{{ end -}}