Skip to content

Commit

Permalink
fix: move enableMermaid out of this map (#1409)
Browse files Browse the repository at this point in the history
* fix: move mermaid out of this map

* enableComment

* enableTablesort

* enableTablesort

* enableEcharts

* enableSharer

* enableTabs

* enableMusic

* enableAplayer

* enableMapbox

* enableAplayer

* enableMath

* counter

* scriptArr

* styleArr
  • Loading branch information
HEIGE-PCloud authored Dec 23, 2024
1 parent a78515e commit 6839e84
Show file tree
Hide file tree
Showing 17 changed files with 30 additions and 30 deletions.
2 changes: 1 addition & 1 deletion layouts/_default/_markup/render-codeblock-mermaid.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<pre class="mermaid">
{{- .Inner | safeHTML }}
</pre>
{{- .Page.Scratch.SetInMap "this" "mermaid" true -}}
{{- .Page.Scratch.Set "enableMermaid" true -}}
2 changes: 1 addition & 1 deletion layouts/_default/_markup/render-passthrough.html
Original file line number Diff line number Diff line change
@@ -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 -}}
Expand Down
2 changes: 1 addition & 1 deletion layouts/_default/baseof.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
</a>

{{- /* comment button */ -}}
{{- if (.Page.Scratch.Get "this").commentEnabled -}}
{{- if .Page.Scratch.Get "enableComment" -}}
<a href="#comments" id="view-comments" class="fixed-button" title="{{ T `viewComments` }}">
{{ partial "plugin/fontawesome.html" (dict "Style" "solid" "Icon" "comment") }}
</a>
Expand Down
2 changes: 1 addition & 1 deletion layouts/_default/single.html
Original file line number Diff line number Diff line change
@@ -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" -}}
<div class="page single special print:!tw-w-full print:!tw-max-w-none print:!tw-m-0 print:!tw-p-0">
{{- /* Title */ -}}
Expand Down
22 changes: 11 additions & 11 deletions layouts/partials/assets.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 -}}
Expand Down Expand Up @@ -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 -}}
Expand All @@ -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 -}}
Expand Down Expand Up @@ -143,15 +143,15 @@
{{- end -}}

{{- /* mermaid */ -}}
{{- if (.Scratch.Get "this").mermaid -}}
{{- if .Scratch.Get "enableMermaid" -}}
<script type="module">
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.esm.min.mjs';
mermaid.initialize({ startOnLoad: true, theme: (window.theme === 'dark' ? 'dark' : 'default') });
</script>
{{- end -}}

{{- /* ECharts */ -}}
{{- if (.Scratch.Get "this").echarts -}}
{{- if .Scratch.Get "enableEcharts" -}}
{{- $config = dict "echarts" true | merge $config -}}
{{- $options := dict -}}
{{- $shims := dict "echarts" "js/shims/echarts.js" -}}
Expand All @@ -171,7 +171,7 @@
{{- end -}}

{{- /* Mapbox GL */ -}}
{{- if (.Scratch.Get "this").mapbox -}}
{{- if .Scratch.Get "enableMapbox" -}}
{{- $source := $cdn.mapboxGLCSS | default "lib/mapbox-gl/mapbox-gl.min.css" -}}
{{- dict "Source" $source "Fingerprint" $fingerprint | dict "Scratch" .Scratch "Data" | partial "scratch/style.html" -}}
{{- $source := $cdn.mapboxGLJS | default "lib/mapbox-gl/mapbox-gl.min.js" -}}
Expand All @@ -180,14 +180,14 @@
{{- $config = dict "accessToken" $params.mapbox.accessToken "RTLTextPlugin" "https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-rtl-text/v0.2.0/mapbox-gl-rtl-text.js" | dict "mapbox" | merge $config -}}
{{- end -}}

{{- if (.Scratch.Get "this").tabs -}}
{{- if .Scratch.Get "enableTabs" -}}
{{- /* <script type="module" src="https://cdn.jsdelivr.net/npm/@github/tab-container-element@4.5.0/dist/bundle.js"></script> */ -}}
{{- $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" -}}
Expand All @@ -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" -}}
Expand Down Expand Up @@ -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" -}}
Expand All @@ -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 -}}

Expand Down
2 changes: 1 addition & 1 deletion layouts/partials/comment.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{{- $commentConfig := dict -}}

{{- if $comment.enable -}}
{{- .Scratch.SetInMap "this" "commentEnabled" true -}}
{{- .Scratch.Set "enableComment" true -}}
<div id="comments" class="print:!tw-hidden tw-pt-32 tw-pb-8">
{{- /* Disqus Comment System */ -}}
{{- $disqus := $comment.disqus | default dict -}}
Expand Down
4 changes: 2 additions & 2 deletions layouts/partials/function/id.html
Original file line number Diff line number Diff line change
Expand Up @@ -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" -}}
Expand Down
2 changes: 1 addition & 1 deletion layouts/partials/plugin/share.html
Original file line number Diff line number Diff line change
@@ -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 -}}
Expand Down
2 changes: 1 addition & 1 deletion layouts/posts/single.html
Original file line number Diff line number Diff line change
@@ -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 -}}
Expand Down
2 changes: 1 addition & 1 deletion layouts/shortcodes/aplayer.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
{{- $_ = replace $_ ",]" "]" -}}
<div class="aplayer-shortcode" {{- printf "data-audio='%s'" $_ | safeHTMLAttr -}} {{- printf "data-options='%s'" $options | safeHTMLAttr -}}></div>

{{- .Page.Scratch.SetInMap "this" "aplayer" true -}}
{{- .Page.Scratch.Set "enableAplayer" true -}}

{{- else -}}
{{- errorf "Only named params is supported: %s" .Position -}}
Expand Down
2 changes: 1 addition & 1 deletion layouts/shortcodes/echarts.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
{{- $width := cond .IsNamedParams (.Get "width") (.Get 0) | default "100%" -}}
{{- $height := cond .IsNamedParams (.Get "height") (.Get 1) | default "30rem" -}}
<div class="echarts" id="{{ $id }}" style="width: {{ $width }}; height: {{ $height }};"></div>
{{- .Page.Scratch.SetInMap "this" "echarts" true -}}
{{- .Page.Scratch.Set "enableEcharts" true -}}
2 changes: 1 addition & 1 deletion layouts/shortcodes/mapbox.html
Original file line number Diff line number Diff line change
Expand Up @@ -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" -}}
<div class="mapbox" id="{{ $id }}" style="width: {{ $width }}; height: {{ $height }};"></div>
{{- .Page.Scratch.SetInMap "this" "mapbox" true -}}
{{- .Page.Scratch.Set "enableMapbox" true -}}
2 changes: 1 addition & 1 deletion layouts/shortcodes/mermaid.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<pre class="mermaid">
{{- .Inner | safeHTML }}
</pre>
{{- .Page.Scratch.SetInMap "this" "mermaid" true -}}
{{- .Page.Scratch.Set "enableMermaid" true -}}
2 changes: 1 addition & 1 deletion layouts/shortcodes/music.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@
{{- else -}}
<meting-js server="{{ .Get 0 }}" type="{{ .Get 1 }}" id="{{ .Get 2 }}" theme="{{ $theme }}"></meting-js>
{{- end -}}
{{- .Page.Scratch.SetInMap "this" "music" true -}}
{{- .Page.Scratch.Set "enableMusic" true -}}
4 changes: 2 additions & 2 deletions layouts/shortcodes/script.html
Original file line number Diff line number Diff line change
@@ -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" -}}
4 changes: 2 additions & 2 deletions layouts/shortcodes/style.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
{{- printf `<%v id="%v">%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" -}}
2 changes: 1 addition & 1 deletion layouts/shortcodes/tabs.html
Original file line number Diff line number Diff line change
@@ -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 -}}
Expand Down

0 comments on commit 6839e84

Please sign in to comment.