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 highLight = true
kaTex = false kaTex = false
collapsibleSidebar = false collapsibleSidebar = false
mermaid = true

View File

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

View File

@ -65,7 +65,7 @@
<script src="{{ $katexAutoRender.RelPermalink }}" onload="renderMathInElement(document.body);" defer></script> <script src="{{ $katexAutoRender.RelPermalink }}" onload="renderMathInElement(document.body);" defer></script>
{{ end -}} {{ end -}}
<script src="{{ $js.RelPermalink }}" defer></script> <script src="{{ $js.RelPermalink }}" defer></script>
{{ if .Site.Params.options.mermaid -}} {{ with .Params.mermaid -}}
<script src="{{ $mermaid.RelPermalink }}" defer></script> <script src="{{ $mermaid.RelPermalink }}" defer></script>
{{ end -}} {{ end -}}
{{ if .Site.Params.options.flexSearch -}} {{ if .Site.Params.options.flexSearch -}}
@ -90,7 +90,7 @@
<script src="{{ $katexAutoRender.RelPermalink }}" integrity="{{ $katexAutoRender.Data.Integrity }}" crossorigin="anonymous" defer></script> <script src="{{ $katexAutoRender.RelPermalink }}" integrity="{{ $katexAutoRender.Data.Integrity }}" crossorigin="anonymous" defer></script>
{{ end -}} {{ end -}}
<script src="{{ $js.RelPermalink }}" integrity="{{ $js.Data.Integrity }}" crossorigin="anonymous" defer></script> <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> <script src="{{ $mermaid.RelPermalink }}" integrity="{{ $mermaid.Data.Integrity }}" crossorigin="anonymous" defer></script>
{{ end -}} {{ end -}}
{{ if .Site.Params.options.flexSearch -}} {{ 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 }}"> <div class="mermaid{{ with .Get "class" }} {{ . }}{{ end }}">
{{ $data := replaceRE "(^\\s+```)" "" .Inner -}} {{ $data := replaceRE "(^\\s+```)" "" .Inner -}}
{{ replaceRE "(```\\s+$)" "" $data -}} {{ replaceRE "(```\\s+$)" "" $data -}}
</div> </div>
{{ else -}} {{ 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 -}} {{ end -}}