From 3c3f6084ccefb2591dde54821b4ad9e52a148f33 Mon Sep 17 00:00:00 2001 From: Cell <1024@lruihao.cn> Date: Thu, 14 Aug 2025 21:29:12 +0800 Subject: [PATCH] :bug: Fix: dirty hack for Mermaid loading --- assets/js/theme.js | 38 ++++++++++++++++++++----------- layouts/_partials/init/index.html | 2 +- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/assets/js/theme.js b/assets/js/theme.js index 5aa6f5f7..d8259689 100644 --- a/assets/js/theme.js +++ b/assets/js/theme.js @@ -695,21 +695,33 @@ class FixIt { await loadMermaid(); }; - this.switchThemeEventSet.add(() => { - if (processing) { - console.warn('Mermaid is still processing, delaying the reload.'); - delayTask = reloadMermaid; - return; - } - // console.log('reload immediately'); - reloadMermaid().catch(console.error); - }); + const waitForMermaid = () => { + return new Promise((resolve) => { + const timer = setInterval(() => { + if (window.mermaid && window.mermaid.initialize) { + clearInterval(timer); + resolve(); + } + }, 100); + }); + }; - this.beforeprintEventSet.add(() => { - // Optionally set theme to 'neutral' for printing if required - }); + waitForMermaid().then(() => { + loadMermaid(); + this.switchThemeEventSet.add(() => { + if (processing) { + console.warn('Mermaid is still processing, delaying the reload.'); + delayTask = reloadMermaid; + return; + } + // console.log('reload immediately'); + reloadMermaid().catch(console.error); + }); - loadMermaid(); + this.beforeprintEventSet.add(() => { + // Optionally set theme to 'neutral' for printing if required + }); + }) } initEcharts() { diff --git a/layouts/_partials/init/index.html b/layouts/_partials/init/index.html index ba826974..53246bd5 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-20250814015310-08d3c62b" -}} +{{- hugo.Store.Set "version" "v0.4.0-alpha-20250814132913-e04bb611" -}} {{- .Store.Set "this" dict -}} {{- partial "init/detection-env.html" . -}}