diff --git a/assets/js/lib/mermaid.js b/assets/js/lib/mermaid.js index dd04fe27..af9d24aa 100644 --- a/assets/js/lib/mermaid.js +++ b/assets/js/lib/mermaid.js @@ -1,7 +1,6 @@ {{- /* Page level params is not supported */ -}} {{- $mermaid := .Site.Params.mermaid -}} {{- $mermaidCDN := $mermaid.cdn | default "https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.esm.min.mjs" -}} -{{- $wrapped := $mermaid.wrapper | default true -}} import mermaid from "{{ $mermaidCDN }}" {{- with $mermaid.zenuml }} @@ -32,13 +31,12 @@ let mermaidContainerObserver = null let mermaidRenderLock = Promise.resolve() let mermaidConfigKey = '' let mermaidIdSeq = 0 -{{- if $wrapped }} +// Panzoom states let panzoomInstances = null let panzoomWheelHosts = null let panzoomEventBound = false let mermaidThemeSyncBound = false let mermaidPanzoomGroups = null -{{- end }} /** * Waits for the next animation frame. @@ -48,7 +46,6 @@ function nextFrame() { return new Promise((resolve) => requestAnimationFrame(resolve)) } -{{- if $wrapped }} /** * Gets (and initializes) the panzoom shared state for a Mermaid diagram container. * @@ -113,7 +110,6 @@ function applyPanzoomTransform(instance, transform) { instance.zoom(transform.scale, { animate: false, force: true }) setTimeout(() => instance.pan(transform.x, transform.y, { animate: false, force: true })) } -{{- end }} /** * Schedule task at idle time to avoid blocking critical rendering. @@ -355,7 +351,6 @@ function observeMermaidContainers(root = document, refresh = false) { }) } -{{- if $wrapped }} /** * Gets the currently visible SVG for a diagram block that contains multiple Mermaid layers. * @param {Element} root @@ -574,7 +569,6 @@ function bindRenderedPanzoom() { bindMermaidPanzoom(document.getElementById(svgId)) }) } -{{- end }} /** * Binds a listener so Mermaid diagrams inside a tab panel render after tab switches. @@ -593,7 +587,6 @@ function bindTabContainerChanged() { }) } -{{- if $wrapped }} /** * Binds theme switch synchronization for Panzoom transforms across Mermaid layers. * @returns {void} @@ -664,7 +657,6 @@ function bindThemeSync() { }) } } -{{- end }} /** * Initializes Mermaid rendering, events, lazy loading and diagram controls. @@ -678,11 +670,9 @@ async function init() { 'color: #FF3670; font-weight: bold; font-size: 16px; text-shadow: 1px 1px 2px rgba(0,0,0,0.1);', ) -{{- if $wrapped }} initDiagramControls() bindRenderedPanzoom() bindThemeSync() -{{- end }} bindTabContainerChanged() // Core: observe containers and render only when they become visible. diff --git a/layouts/_markup/render-codeblock-echarts.html b/layouts/_markup/render-codeblock-echarts.html index c761ac2b..5cb209f2 100644 --- a/layouts/_markup/render-codeblock-echarts.html +++ b/layouts/_markup/render-codeblock-echarts.html @@ -3,9 +3,6 @@ "Inner" .Inner "Resources" .Page.Resources "Position" .Position + "Page" .Page | partial "plugin/echarts.html" -}} -{{- .Page.Store.Set "hasEcharts" true -}} -{{- if eq hugo.Context.MarkupScope "home" -}} - {{- site.Home.Store.Set "hasEcharts" true -}} -{{- end -}} diff --git a/layouts/_markup/render-codeblock-json.html b/layouts/_markup/render-codeblock-json.html index e59b438b..64bac373 100644 --- a/layouts/_markup/render-codeblock-json.html +++ b/layouts/_markup/render-codeblock-json.html @@ -1,5 +1,5 @@ {{- $jsonViewer := .Attributes | merge .Page.Params.jsonViewer | merge .Page.Site.Params.jsonViewer -}} -{{- if $jsonViewer.enable -}} +{{- if $jsonViewer.enable | and (ne hugo.Context.MarkupScope "home") -}} {{- $attrs := printf `expand-depth="%v"` $jsonViewer.expanddepth -}} {{- $copyable := false -}} {{- with $jsonViewer.copyable -}} @@ -13,9 +13,6 @@ {{- end -}} {{- .Page.Store.Set "hasJsonViewer" true -}} - {{- if eq hugo.Context.MarkupScope "home" -}} - {{- site.Home.Store.Set "hasJsonViewer" true -}} - {{- end -}} {{- else -}} {{- partial "plugin/code-block-wrapper.html" . -}} {{- end -}} diff --git a/layouts/_markup/render-codeblock-mermaid.html b/layouts/_markup/render-codeblock-mermaid.html index 2f0f6cad..64eeca73 100644 --- a/layouts/_markup/render-codeblock-mermaid.html +++ b/layouts/_markup/render-codeblock-mermaid.html @@ -1,5 +1 @@ -{{- 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 -}} +{{- dict "Options" .Attributes "Inner" .Inner "Page" .Page | partial "plugin/mermaid.html" -}} diff --git a/layouts/_markup/render-passthrough.html b/layouts/_markup/render-passthrough.html index 8dcaef8e..4288fdc1 100644 --- a/layouts/_markup/render-passthrough.html +++ b/layouts/_markup/render-passthrough.html @@ -13,7 +13,7 @@ Regular passthrough rendering: - [todo] support more features in future */ -}} -{{- if $math.enable -}} +{{- if $math.enable | and (ne hugo.Context.MarkupScope "home") -}} {{- if eq $math.type "katex" -}} {{- $katex := $math.katex -}} {{- $opts := dict "output" "htmlAndMathml" "displayMode" (eq $.Type "block") }} @@ -29,9 +29,6 @@ {{- else }} {{- .Value }} {{- $.Page.Store.Set "hasKaTeX" true -}} - {{- if eq hugo.Context.MarkupScope "home" -}} - {{- site.Home.Store.Set "hasKaTeX" true -}} - {{- end -}} {{- end }} {{- end -}} {{- else if eq $math.type "mathjax" -}} @@ -41,9 +38,6 @@ ${{ .Inner }}$ {{- end -}} {{- $.Page.Store.Set "hasMathJax" true -}} - {{- if eq hugo.Context.MarkupScope "home" -}} - {{- site.Home.Store.Set "hasMathJax" true -}} - {{- end -}} {{- end -}} {{- else -}} {{- /* Regular passthrough rendering */ -}} diff --git a/layouts/_partials/layouts/assets.html b/layouts/_partials/layouts/assets.html index aa41afb6..4af77340 100644 --- a/layouts/_partials/layouts/assets.html +++ b/layouts/_partials/layouts/assets.html @@ -348,7 +348,7 @@ FixIt theme assets partial {{- /* Mermaid plugin */ -}} {{- if .Store.Get "hasMermaid" | and (not $isArchivesOrOffline) -}} - {{- if .Site.Params.mermaid.wrapper -}} + {{- if .Store.Get "hasPanzoom" -}} {{- $source := $cdn.panzoomJS | default "lib/panzoom/panzoom.min.js" -}} {{- dict "Source" $source "Fingerprint" $fingerprint "Defer" true | dict "Page" $ "Data" | partial "store/script.html" -}} {{- end -}} diff --git a/layouts/_partials/plugin/analytics.html b/layouts/_partials/plugin/analytics.html index 949651ae..f16ee090 100644 --- a/layouts/_partials/plugin/analytics.html +++ b/layouts/_partials/plugin/analytics.html @@ -1,3 +1,11 @@ +{{- /* + Analytics script injector. + - Reads analytics config from Site Store. + - Conditionally renders provider snippets when enabled. + - Supported providers include Google, Fathom, Baidu, Umami, and others. + @param {Object} .Site Hugo site object +*/ -}} + {{- $analytics := .Site.Store.Get "analytics" | default dict -}} {{- if $analytics.enable -}} diff --git a/layouts/_partials/plugin/code-block-wrapper.html b/layouts/_partials/plugin/code-block-wrapper.html index f50d2c50..ef3c2586 100644 --- a/layouts/_partials/plugin/code-block-wrapper.html +++ b/layouts/_partials/plugin/code-block-wrapper.html @@ -1,4 +1,14 @@ -{{- /* Hook for code blocks rendering */ -}} +{{- /* + Code block wrapper hook for highlight output. + - Applies wrapper UI features based on codeblock config. + - Supports classic/modern modes, copy button, expand button, and line-number states. + @param {Object} .Attributes code block attributes + @param {Object} .Options code fence options + @param {String} .Inner raw code content + @param {Object} .Page current page context + @param {String} .Type language/type for current block +*/ -}} + {{- $config := .Attributes | merge .Page.Params.codeblock | merge .Page.Site.Params.codeblock -}} {{- $result := transform.HighlightCodeBlock . -}} {{- $wrapper := $result.Wrapped -}} diff --git a/layouts/_partials/plugin/diagram-copy-btn.html b/layouts/_partials/plugin/diagram-copy-btn.html index 7d9820e8..5aadee74 100644 --- a/layouts/_partials/plugin/diagram-copy-btn.html +++ b/layouts/_partials/plugin/diagram-copy-btn.html @@ -1,4 +1,8 @@ -{{- /* Diagram copy button */ -}} +{{- /* + Copy button for diagram-like plugins. + @param {String} [.Label] aria label text for copy action +*/ -}} + {{- $label := .Label | default "Copy Diagram code" -}}