diff --git a/assets/js/lib/mermaid.js b/assets/js/lib/mermaid.js index 21d9fc97..7b7ab2b1 100644 --- a/assets/js/lib/mermaid.js +++ b/assets/js/lib/mermaid.js @@ -78,8 +78,12 @@ async function loadMermaid({ theme, darkMode, selector }) { } async function initMermaid() { - const contentEl = document.getElementById('content'); - if (!contentEl || !contentEl.innerHTML) return + const mermaidElements = document.querySelectorAll('.mermaid, .mermaid-dark, .mermaid-neutral') + if (!mermaidElements.length) return + console.log( + `%c💫 FixIt Mermaid`, + 'color: #FF3670; font-weight: bold; font-size: 16px; text-shadow: 1px 1px 2px rgba(0,0,0,0.1);', + ) const currentTheme = getTheme() const nextTheme = getTheme(true) const darkMode = document.documentElement.dataset.theme === 'dark' @@ -95,11 +99,6 @@ window.FixItMermaid = { } window.mermaid = mermaid -console.log( - `%c💫 FixIt Mermaid`, - 'color: #FF3670; font-weight: bold; font-size: 16px; text-shadow: 1px 1px 2px rgba(0,0,0,0.1);', -) - if (document.readyState !== 'loading') { initMermaid() } else { diff --git a/layouts/_markup/render-codeblock-mermaid.html b/layouts/_markup/render-codeblock-mermaid.html index cb0afbc3..2f0f6cad 100644 --- a/layouts/_markup/render-codeblock-mermaid.html +++ b/layouts/_markup/render-codeblock-mermaid.html @@ -1,2 +1,5 @@ {{- dict "Options" .Attributes "Inner" .Inner | partial "plugin/mermaid.html" -}} {{- .Page.Store.Set "hasMermaid" true -}} +{{- if eq hugo.Context.MarkupScope "home" -}} + {{- site.Home.Store.Set "hasMermaid" true -}} +{{- end -}} diff --git a/layouts/_partials/init/index.html b/layouts/_partials/init/index.html index bff7ddb8..ba64e009 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-20250820030120-93acf8ea" -}} +{{- hugo.Store.Set "version" "v0.4.0-alpha-20250820033711-d4305d9b" -}} {{- .Store.Set "this" dict -}} {{- partial "init/detection-env.html" . -}} diff --git a/test/content/posts/mermaid-diagrams-test.md b/test/content/posts/mermaid-diagrams-test.md index 83c0b9f6..a9b36846 100644 --- a/test/content/posts/mermaid-diagrams-test.md +++ b/test/content/posts/mermaid-diagrams-test.md @@ -17,8 +17,6 @@ The FixIt theme supports two ways to use Mermaid: code block syntax and shortcod ## Flowchart -### Code Block Syntax - ```mermaid flowchart TD A[Start] --> B{Is it?} @@ -28,15 +26,7 @@ flowchart TD B ---->|No| E[End] ``` -### Shortcode Syntax - -{{< mermaid >}} -flowchart LR - A[Hard edge] -->|Link text| B(Round edge) - B --> C{Decision} - C -->|One| D[Result one] - C -->|Two| E[Result two] -{{< /mermaid >}} + ## Sequence Diagram diff --git a/test/hugo.toml b/test/hugo.toml index ae52c5f4..7e26aded 100644 --- a/test/hugo.toml +++ b/test/hugo.toml @@ -47,3 +47,6 @@ baseURL = "https://demo.fixit.lruihao.cn/test/" [params.mermaid] zenuml = "https://cdn.jsdelivr.net/npm/@mermaid-js/mermaid-zenuml/dist/mermaid-zenuml.esm.min.mjs" + + [params.home.posts] + paginate = 1