diff --git a/go.mod b/go.mod index f3f52c9..2a72fd3 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,5 @@ module github.com/hugomods/mermaid go 1.19 + +require github.com/hugomods/hugopress v0.5.0 // indirect diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..6ec9408 --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/hugomods/hugopress v0.5.0 h1:eQHg1aKnc5StGFnV5H0BORhE0UmHYpaWHnX9QNseHrw= +github.com/hugomods/hugopress v0.5.0/go.mod h1:CRYvr60xOkZOf4Atkuj+uEj2EH5pjJ39Ws3aJAkoMkA= diff --git a/hugo.toml b/hugo.toml index ae131fb..1cc4633 100644 --- a/hugo.toml +++ b/hugo.toml @@ -2,6 +2,9 @@ min = "0.110.0" [params.hugopress.modules.mermaid.hooks.body-end] +partial = "mermaid/assets/js" +cacheable = true +cache_store_key = "hasMermaid" [params.mermaid] js_url = "https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.esm.min.mjs" diff --git a/layouts/partials/mermaid/assets/js.html b/layouts/partials/mermaid/assets/js.html index b7927ca..d714aec 100644 --- a/layouts/partials/mermaid/assets/js.html +++ b/layouts/partials/mermaid/assets/js.html @@ -1,4 +1,4 @@ -{{- if or (.HasShortcode "mermaid") (.Store.Get "hasMermaid") }} +{{- if .Store.Get "hasMermaid" }} diff --git a/layouts/shortcodes/mermaid.html b/layouts/shortcodes/mermaid.html index 7a55959..20ec319 100644 --- a/layouts/shortcodes/mermaid.html +++ b/layouts/shortcodes/mermaid.html @@ -1,3 +1,4 @@ +{{ .Page.Store.Set "hasMermaid" true -}}
     {{- .Inner | safeHTML -}}