From 6839e840aec714f8c32ff42239151a497e588df1 Mon Sep 17 00:00:00 2001 From: PCloud Date: Mon, 23 Dec 2024 10:54:33 +0000 Subject: [PATCH] fix: move enableMermaid out of `this` map (#1409) * fix: move mermaid out of this map * enableComment * enableTablesort * enableTablesort * enableEcharts * enableSharer * enableTabs * enableMusic * enableAplayer * enableMapbox * enableAplayer * enableMath * counter * scriptArr * styleArr --- .../_markup/render-codeblock-mermaid.html | 2 +- .../_default/_markup/render-passthrough.html | 2 +- layouts/_default/baseof.html | 2 +- layouts/_default/single.html | 2 +- layouts/partials/assets.html | 22 +++++++++---------- layouts/partials/comment.html | 2 +- layouts/partials/function/id.html | 4 ++-- layouts/partials/plugin/share.html | 2 +- layouts/posts/single.html | 2 +- layouts/shortcodes/aplayer.html | 2 +- layouts/shortcodes/echarts.html | 2 +- layouts/shortcodes/mapbox.html | 2 +- layouts/shortcodes/mermaid.html | 2 +- layouts/shortcodes/music.html | 2 +- layouts/shortcodes/script.html | 4 ++-- layouts/shortcodes/style.html | 4 ++-- layouts/shortcodes/tabs.html | 2 +- 17 files changed, 30 insertions(+), 30 deletions(-) diff --git a/layouts/_default/_markup/render-codeblock-mermaid.html b/layouts/_default/_markup/render-codeblock-mermaid.html index e5c4890a2..0b7eb3195 100644 --- a/layouts/_default/_markup/render-codeblock-mermaid.html +++ b/layouts/_default/_markup/render-codeblock-mermaid.html @@ -1,4 +1,4 @@
     {{- .Inner | safeHTML }}
 
-{{- .Page.Scratch.SetInMap "this" "mermaid" true -}} +{{- .Page.Scratch.Set "enableMermaid" true -}} diff --git a/layouts/_default/_markup/render-passthrough.html b/layouts/_default/_markup/render-passthrough.html index ab46d3f23..b5dd844dc 100644 --- a/layouts/_default/_markup/render-passthrough.html +++ b/layouts/_default/_markup/render-passthrough.html @@ -1,4 +1,4 @@ -{{- .Page.Scratch.SetInMap "this" "math" true -}} +{{- .Page.Scratch.Set "enableMath" true -}} {{- if eq .Type "block" -}} {{- $opts := dict "displayMode" true "output" "html" -}} {{- transform.ToMath .Inner $opts -}} diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html index 75197ba91..4f267fdc8 100644 --- a/layouts/_default/baseof.html +++ b/layouts/_default/baseof.html @@ -89,7 +89,7 @@ {{- /* comment button */ -}} - {{- if (.Page.Scratch.Get "this").commentEnabled -}} + {{- if .Page.Scratch.Get "enableComment" -}} {{ partial "plugin/fontawesome.html" (dict "Style" "solid" "Icon" "comment") }} diff --git a/layouts/_default/single.html b/layouts/_default/single.html index ed8181d8c..8021c6b99 100644 --- a/layouts/_default/single.html +++ b/layouts/_default/single.html @@ -1,7 +1,7 @@ {{- define "title" }}{{ .Title }} - {{ .Site.Title }}{{ end -}} {{- define "content" -}} - {{- .Page.Scratch.SetInMap "this" "tablesort" true -}} + {{- .Page.Scratch.Set "enableTablesort" true -}} {{- $params := .Scratch.Get "params" -}}
{{- /* Title */ -}} diff --git a/layouts/partials/assets.html b/layouts/partials/assets.html index 612d85216..3f3647413 100644 --- a/layouts/partials/assets.html +++ b/layouts/partials/assets.html @@ -28,7 +28,7 @@ {{- end -}} {{- /* tablesort */ -}} -{{- if $params.table | and $params.table.sort | and (.Scratch.Get "this").tablesort -}} +{{- if $params.table | and $params.table.sort | and (.Scratch.Get "enableTablesort") -}} {{- $source := $cdn.tablesort | default "lib/tablesort/tablesort.min.js" -}} {{- dict "Source" $source "Fingerprint" $fingerprint | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}} {{- $config = dict "sort" true | dict "table" | merge $config -}} @@ -65,7 +65,7 @@ {{- end -}} {{- /* Sharer.js */ -}} -{{- if $params.share.enable | and (.Scratch.Get "this").sharer -}} +{{- if $params.share.enable | and (.Scratch.Get "enableSharer") -}} {{- $source := $cdn.sharerJS | default "lib/sharer/sharer.min.js" -}} {{- dict "Source" $source "Fingerprint" $fingerprint | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}} {{- $config = dict "sharerjs" true | merge $config -}} @@ -80,7 +80,7 @@ {{- end -}} {{- /* KaTeX */ -}} -{{- if (.Scratch.Get "this").math -}} +{{- if .Scratch.Get "enableMath" -}} {{- $source := $cdn.katexCSS | default "lib/katex/katex.min.css" -}} {{- dict "Source" $source "Fingerprint" $fingerprint | dict "Scratch" .Scratch "Data" | partial "scratch/style.html" -}} {{- end -}} @@ -143,7 +143,7 @@ {{- end -}} {{- /* mermaid */ -}} -{{- if (.Scratch.Get "this").mermaid -}} +{{- if .Scratch.Get "enableMermaid" -}} */ -}} {{- $source := $cdn.tabsjs | default "lib/tabs/tabs.min.js" -}} {{- dict "Source" $source "Fingerprint" $fingerprint "Defer" true "Module" true | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}} {{- end -}} {{- /* Music */ -}} -{{- if (.Scratch.Get "this").aplayer | or (.Scratch.Get "this").music -}} +{{- if (.Scratch.Get "enableAplayer") | or (.Scratch.Get "enableMusic") -}} {{- /* APlayer */ -}} {{- $source := $cdn.aplayerCSS | default "lib/aplayer/APlayer.min.css" -}} {{- dict "Source" $source "Fingerprint" $fingerprint "Defer" true | dict "Scratch" .Scratch "Data" | partial "scratch/style.html" -}} @@ -196,7 +196,7 @@ {{- $source := $cdn.aplayerJS | default "lib/aplayer/APlayer.min.js" -}} {{- dict "Source" $source "Fingerprint" $fingerprint "Defer" true | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}} - {{- if (.Scratch.Get "this").music -}} + {{- if (.Scratch.Get "enableMusic") -}} {{- /* MetingJS */ -}} {{- $source := $cdn.metingJS | default "lib/meting/Meting.min.js" -}} {{- dict "Source" $source "Fingerprint" $fingerprint "Defer" true | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}} @@ -264,7 +264,7 @@ {{- end -}} {{/* Custom style */}} -{{- with (.Scratch.Get "this").styleArr -}} +{{- with .Scratch.Get "styleArr" -}} {{- $content := delimit . "" -}} {{- $path := substr (md5 $content) 0 6 | printf "css/%v" -}} {{- $options := printf "%v.min.css" $path | dict "targetPath" -}} @@ -286,7 +286,7 @@ {{- $_ := $js.RelPermalink -}} {{- dict "Link" $js.RelPermalink "Fingerprint" $fingerprint "Defer" true | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}} -{{- with (.Scratch.Get "this").scriptArr -}} +{{- with .Scratch.Get "scriptArr" -}} {{- delimit . "\n" | dict "Content" | dict "Scratch" $.Scratch "Data" | partial "scratch/script.html" -}} {{- end -}} diff --git a/layouts/partials/comment.html b/layouts/partials/comment.html index ae1b54ee5..c04c18bd6 100644 --- a/layouts/partials/comment.html +++ b/layouts/partials/comment.html @@ -4,7 +4,7 @@ {{- $commentConfig := dict -}} {{- if $comment.enable -}} - {{- .Scratch.SetInMap "this" "commentEnabled" true -}} + {{- .Scratch.Set "enableComment" true -}}
{{- /* Disqus Comment System */ -}} {{- $disqus := $comment.disqus | default dict -}} diff --git a/layouts/partials/function/id.html b/layouts/partials/function/id.html index 1326d3a0c..5e080e867 100644 --- a/layouts/partials/function/id.html +++ b/layouts/partials/function/id.html @@ -5,9 +5,9 @@ {{- /* If an ID is specified, then just use it.*/ -}} {{- $id = printf "%v" . -}} {{- else -}} - {{- $count := ($.Scratch.Get "this").count | default 1 -}} + {{- $count := ($.Scratch.Get "counter") | default 1 -}} {{- $id = printf "id-%d" $count -}} - {{- $count | add 1 | $.Scratch.SetInMap "this" "count" -}} + {{- $count | add 1 | $.Scratch.Set "counter" -}} {{- end -}} {{- with .Content -}} {{- dict $id . | dict "data" | dict "config" | merge ($.Scratch.Get "this") | $.Scratch.Set "this" -}} diff --git a/layouts/partials/plugin/share.html b/layouts/partials/plugin/share.html index f94866de7..718793aa9 100644 --- a/layouts/partials/plugin/share.html +++ b/layouts/partials/plugin/share.html @@ -1,5 +1,5 @@ {{- $share := (.Scratch.Get "params").share | default dict -}} -{{- .Page.Scratch.SetInMap "this" "sharer" true -}} +{{- .Page.Scratch.Set "enableSharer" true -}} {{- if $share.enable -}} {{- /* 001: Twitter */ -}} {{- if $share.Twitter -}} diff --git a/layouts/posts/single.html b/layouts/posts/single.html index 5aa7464d2..ce31b4a26 100644 --- a/layouts/posts/single.html +++ b/layouts/posts/single.html @@ -1,7 +1,7 @@ {{- define "title" }}{{ .Title }} - {{ .Site.Title }}{{ end -}} {{- define "content" -}} - {{- .Page.Scratch.SetInMap "this" "tablesort" true -}} + {{- .Page.Scratch.Set "enableTablesort" true -}} {{- $params := .Scratch.Get "params" -}} {{- $toc := $params.toc -}} {{- if eq $toc true -}} diff --git a/layouts/shortcodes/aplayer.html b/layouts/shortcodes/aplayer.html index 276cc48cc..7351f4b5f 100644 --- a/layouts/shortcodes/aplayer.html +++ b/layouts/shortcodes/aplayer.html @@ -20,7 +20,7 @@ {{- $_ = replace $_ ",]" "]" -}}
- {{- .Page.Scratch.SetInMap "this" "aplayer" true -}} + {{- .Page.Scratch.Set "enableAplayer" true -}} {{- else -}} {{- errorf "Only named params is supported: %s" .Position -}} diff --git a/layouts/shortcodes/echarts.html b/layouts/shortcodes/echarts.html index f13be3608..94ddbd316 100644 --- a/layouts/shortcodes/echarts.html +++ b/layouts/shortcodes/echarts.html @@ -3,4 +3,4 @@ {{- $width := cond .IsNamedParams (.Get "width") (.Get 0) | default "100%" -}} {{- $height := cond .IsNamedParams (.Get "height") (.Get 1) | default "30rem" -}}
-{{- .Page.Scratch.SetInMap "this" "echarts" true -}} +{{- .Page.Scratch.Set "enableEcharts" true -}} diff --git a/layouts/shortcodes/mapbox.html b/layouts/shortcodes/mapbox.html index 516d37032..95a26a89a 100644 --- a/layouts/shortcodes/mapbox.html +++ b/layouts/shortcodes/mapbox.html @@ -30,4 +30,4 @@ {{- $options := dict "lng" $lng "lat" $lat "zoom" $zoom "marked" $marked "lightStyle" $lightStyle "darkStyle" $darkStyle "geolocate" $geolocate "navigation" $navigation "scale" $scale "fullscreen" $fullscreen -}} {{- $id := dict "Content" $options "Scratch" .Page.Scratch | partial "function/id.html" -}}
-{{- .Page.Scratch.SetInMap "this" "mapbox" true -}} +{{- .Page.Scratch.Set "enableMapbox" true -}} diff --git a/layouts/shortcodes/mermaid.html b/layouts/shortcodes/mermaid.html index e5c4890a2..0b7eb3195 100644 --- a/layouts/shortcodes/mermaid.html +++ b/layouts/shortcodes/mermaid.html @@ -1,4 +1,4 @@
     {{- .Inner | safeHTML }}
 
-{{- .Page.Scratch.SetInMap "this" "mermaid" true -}} +{{- .Page.Scratch.Set "enableMermaid" true -}} diff --git a/layouts/shortcodes/music.html b/layouts/shortcodes/music.html index 904ad5b3d..7da5db1c9 100644 --- a/layouts/shortcodes/music.html +++ b/layouts/shortcodes/music.html @@ -47,4 +47,4 @@ {{- else -}} {{- end -}} -{{- .Page.Scratch.SetInMap "this" "music" true -}} +{{- .Page.Scratch.Set "enableMusic" true -}} diff --git a/layouts/shortcodes/script.html b/layouts/shortcodes/script.html index 278232d3d..d7ecdc70d 100644 --- a/layouts/shortcodes/script.html +++ b/layouts/shortcodes/script.html @@ -1,2 +1,2 @@ -{{- $scriptArr := (.Page.Scratch.Get "this").scriptArr | default slice -}} -{{- $scriptArr | append (trim .Inner "\n") | .Page.Scratch.SetInMap "this" "scriptArr" -}} +{{- $scriptArr := .Page.Scratch.Get "scriptArr" | default slice -}} +{{- $scriptArr | append (trim .Inner "\n") | .Page.Scratch.Set "scriptArr" -}} diff --git a/layouts/shortcodes/style.html b/layouts/shortcodes/style.html index 8e0359602..58f74a5dc 100644 --- a/layouts/shortcodes/style.html +++ b/layouts/shortcodes/style.html @@ -4,5 +4,5 @@ {{- printf `<%v id="%v">%v` $tag $id $content $tag | safeHTML -}} {{- $style := .Get 0 | printf "#%v{%v}" $id -}} -{{- $styleArr := (.Page.Scratch.Get "this").styleArr | default slice -}} -{{- $styleArr | append $style | .Page.Scratch.SetInMap "this" "styleArr" -}} +{{- $styleArr := .Page.Scratch.Get "styleArr" | default slice -}} +{{- $styleArr | append $style | .Page.Scratch.Set "styleArr" -}} diff --git a/layouts/shortcodes/tabs.html b/layouts/shortcodes/tabs.html index 1729ed858..c9f93f1f4 100644 --- a/layouts/shortcodes/tabs.html +++ b/layouts/shortcodes/tabs.html @@ -1,5 +1,5 @@ {{/* Update the global config map so the JavaScript dependency will be loaded */}} -{{- .Page.Scratch.SetInMap "this" "tabs" true -}} +{{- .Page.Scratch.Set "enableTabs" true -}} {{/* Get all children tabs */}} {{- $tabs := .Scratch.Get "tabs" -}} {{ if not $tabs -}}