Skip to content

Commit

Permalink
🐛 Fix: style and script shortcodes missing values in page Scratch
Browse files Browse the repository at this point in the history
  • Loading branch information
Lruihao committed Aug 31, 2024
1 parent c2bcccc commit 9e67e25
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
6 changes: 3 additions & 3 deletions layouts/partials/assets.html
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,8 @@
{{- dict "Source" . "Fingerprint" $fingerprint "Defer" true | dict "Scratch" $.Scratch "Data" | partial "scratch/script.html" -}}
{{- end -}}

{{- with (.Scratch.Get "this").styleArr -}}
{{- $content := delimit . "" -}}
{{- with .Store.Get "styleArr" -}}
{{- $content := delimit . " " -}}
{{- $path := substr (md5 $content) 0 6 | printf "css/%v" -}}
{{- $options := printf "%v.min.css" $path | dict "targetPath" -}}
{{- dict "Content" $content "Path" (printf "%v.scss" $path) "ToCSS" $options | dict "Scratch" $.Scratch "Data" | partial "scratch/style.html" -}}
Expand Down Expand Up @@ -289,7 +289,7 @@
{{- dict "Source" . "Build" $options "Fingerprint" $fingerprint "Defer" true | dict "Scratch" $.Scratch "Data" | partial "scratch/script.html" -}}
{{- end -}}

{{- with (.Scratch.Get "this").scriptArr -}}
{{- with .Store.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/init/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- .Scratch.Set "version" "v0.3.11" -}}
{{- .Scratch.Set "version" "v0.3.12-c2bcccc9" -}}
{{- .Scratch.Set "this" dict -}}

{{- partial "init/detection-env.html" . -}}
Expand Down
7 changes: 5 additions & 2 deletions layouts/shortcodes/script.html
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
{{- $scriptArr := (.Page.Scratch.Get "this").scriptArr | default slice -}}
{{- $scriptArr | append (trim (partial "function/dos2unix.html" .Inner) "\n") | .Page.Scratch.SetInMap "this" "scriptArr" -}}
{{- $scriptArr := .Page.Store.Get "scriptArr" | default slice -}}
{{- $content := trim (partial "function/dos2unix.html" .Inner) "\n" -}}
{{- if not (in $scriptArr $content) -}}
{{- $scriptArr | append $content | .Page.Store.Set "scriptArr" -}}
{{- end -}}
6 changes: 4 additions & 2 deletions layouts/shortcodes/style.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@
{{- 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.Store.Get "styleArr" | default slice -}}
{{- if not (in $styleArr $style) -}}
{{- $styleArr | append $style | .Page.Store.Set "styleArr" -}}
{{- end -}}

0 comments on commit 9e67e25

Please sign in to comment.