From fe034a2a40f400bbebe8cdb248a39e799a7c6aa9 Mon Sep 17 00:00:00 2001 From: Cell <1024@lruihao.cn> Date: Wed, 13 Aug 2025 10:20:23 +0800 Subject: [PATCH] :wrench: Chore(i): Mermaid ZenUML is not enabled by default --- assets/js/theme.js | 8 ++++---- hugo.toml | 7 +++++-- layouts/_partials/assets.html | 7 ++++++- layouts/_partials/init/index.html | 2 +- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/assets/js/theme.js b/assets/js/theme.js index fb62f936..397d8b8f 100644 --- a/assets/js/theme.js +++ b/assets/js/theme.js @@ -649,8 +649,8 @@ class FixIt { }); await window.mermaid.run(); processing = false; - if (delayTask && delayTask instanceof Function) { - delayTask() + if (delayTask && typeof delayTask === 'function') { + await delayTask(); delayTask = null; } }; @@ -660,7 +660,7 @@ class FixIt { el.replaceChild(el.nextElementSibling.content.cloneNode(true), el.firstChild); el.removeAttribute('data-processed'); }); - loadMermaid() + await loadMermaid(); }; this.switchThemeEventSet.add(() => { @@ -670,7 +670,7 @@ class FixIt { return; } // console.log('reload immediately'); - reloadMermaid(); + reloadMermaid().catch(console.error); }); this.beforeprintEventSet.add(() => { diff --git a/hugo.toml b/hugo.toml index 943bcab3..b0e1dd27 100644 --- a/hugo.toml +++ b/hugo.toml @@ -702,9 +702,12 @@ mainSections = [] # See https://github.com/mermaid-js/mermaid [params.mermaid] # FixIt 0.4.0 | NEW Mermaid ESM module CDN source - cdn = "https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.esm.min.mjs" + # default is https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.esm.min.mjs + cdn = "" # FixIt 0.4.0 | NEW ZenUML ESM module CDN source - zenuml = "https://cdn.jsdelivr.net/npm/@mermaid-js/mermaid-zenuml/dist/mermaid-zenuml.esm.min.mjs" + # default is empty, you can set it to a CDN source to enable ZenUML support + # e.g. https://cdn.jsdelivr.net/npm/@mermaid-js/mermaid-zenuml/dist/mermaid-zenuml.esm.min.mjs + zenuml = "" # For values, see https://mermaid.js.org/config/theming.html#available-themes themes = ["default", "dark"] diff --git a/layouts/_partials/assets.html b/layouts/_partials/assets.html index 4f50b864..aa3bb044 100644 --- a/layouts/_partials/assets.html +++ b/layouts/_partials/assets.html @@ -131,7 +131,12 @@ {{- /* mermaid */ -}} {{- if .Store.Get "hasMermaid" -}} {{- $mermaid := .Param "mermaid" -}} - {{- $content := printf "import mermaid from %q; import zenuml from %q; await mermaid.registerExternalDiagrams([zenuml]); window.mermaid = mermaid;" $mermaid.cdn $mermaid.zenuml -}} + {{- $mermaidCDN := $mermaid.cdn | default "https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.esm.min.mjs" -}} + {{- $content := printf "import mermaid from %q;" $mermaidCDN -}} + {{- with $mermaid.zenuml -}} + {{- $content = printf "%v import zenuml from %q; await mermaid.registerExternalDiagrams([zenuml]);" $content . -}} + {{- end -}} + {{- $content = printf "%v window.mermaid = mermaid;" $content -}} {{- dict "Content" $content "Attr" `type="module"` | dict "Page" $ "Data" | partial "store/script.html" -}} {{- $config = dict "themes" $mermaid.themes | dict "mermaid" | merge $config -}} {{- end -}} diff --git a/layouts/_partials/init/index.html b/layouts/_partials/init/index.html index f2342c6c..23395b6f 100644 --- a/layouts/_partials/init/index.html +++ b/layouts/_partials/init/index.html @@ -1,4 +1,4 @@ -{{- hugo.Store.Set "version" "v0.4.0-alpha-20250812094854-45f101a4" -}} +{{- hugo.Store.Set "version" "v0.4.0-alpha-20250813022026-bf3fe683" -}} {{- .Store.Set "this" dict -}} {{- partial "init/detection-env.html" . -}}