Skip to content

Commit

Permalink
perf(hugopress): cache body-end hook
Browse files Browse the repository at this point in the history
  • Loading branch information
razonyang committed Jun 16, 2024
1 parent 979353b commit 2461a6d
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module github.com/hugomods/mermaid

go 1.19

require github.com/hugomods/hugopress v0.5.0 // indirect
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
3 changes: 3 additions & 0 deletions hugo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion layouts/partials/mermaid/assets/js.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if or (.HasShortcode "mermaid") (.Store.Get "hasMermaid") }}
{{- if .Store.Get "hasMermaid" }}
<script type="module">
import mermaid from "{{ .Site.Params.mermaid.js_url }}";
</script>
Expand Down
1 change: 1 addition & 0 deletions layouts/shortcodes/mermaid.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{ .Page.Store.Set "hasMermaid" true -}}
<pre class="mermaid">
{{- .Inner | safeHTML -}}
</pre>

0 comments on commit 2461a6d

Please sign in to comment.