From a87aee984ecb26c07d593a9b185ddd4eb4563259 Mon Sep 17 00:00:00 2001 From: Aditya Telange <21258296+adityatelange@users.noreply.github.com> Date: Sun, 18 Oct 2026 20:02:03 +0530 Subject: [PATCH] refactor(layouts): replace scratch with template variables - replaced deprecated .Scratch with local variables in toc, index.json, share_icons and ltr/rtl shortcodes - replaced newScratch with local variables in post_meta, schema_json and share_icons - keeps state local to each template; output unchanged --- layouts/_partials/post_meta.html | 12 ++++++------ layouts/_partials/share_icons.html | 10 +++++----- layouts/_partials/templates/schema_json.html | 6 +++--- layouts/_partials/toc.html | 17 ++++++----------- layouts/_shortcodes/ltr.html | 8 ++++---- layouts/_shortcodes/rtl.html | 8 ++++---- layouts/index.json | 6 +++--- 7 files changed, 31 insertions(+), 36 deletions(-) diff --git a/layouts/_partials/post_meta.html b/layouts/_partials/post_meta.html index c7c2635d..30da9696 100644 --- a/layouts/_partials/post_meta.html +++ b/layouts/_partials/post_meta.html @@ -1,25 +1,25 @@ -{{- $scratch := newScratch }} +{{- $meta := slice }} {{- if not .Date.IsZero -}} - {{- $scratch.Add "meta" (slice (printf "%s" (.Date) (.Date | time.Format (default ":date_long" site.Params.DateFormat)))) }} + {{- $meta = $meta | append (printf "%s" (.Date) (.Date | time.Format (default ":date_long" site.Params.DateFormat))) }} {{- end }} {{- if (.Param "ShowReadingTime") -}} - {{- $scratch.Add "meta" (slice (printf "%s" (i18n "read_time" .ReadingTime | default (printf "%d min" .ReadingTime)))) }} + {{- $meta = $meta | append (printf "%s" (i18n "read_time" .ReadingTime | default (printf "%d min" .ReadingTime))) }} {{- end }} {{- if (.Param "ShowWordCount") -}} - {{- $scratch.Add "meta" (slice (printf "%s" (i18n "words" .WordCount | default (printf "%d words" .WordCount)))) }} + {{- $meta = $meta | append (printf "%s" (i18n "words" .WordCount | default (printf "%d words" .WordCount))) }} {{- end }} {{- if not (.Param "hideAuthor") -}} {{- with (partial "author.html" .) }} - {{- $scratch.Add "meta" (slice (printf "%s" .)) }} + {{- $meta = $meta | append (printf "%s" .) }} {{- end }} {{- end }} {{/* Combine all meta information into a single string with separators and render it as HTML.*/}} -{{- with ($scratch.Get "meta") }} +{{- with $meta }} {{- delimit . " ยท " | safeHTML -}} {{- end -}} diff --git a/layouts/_partials/share_icons.html b/layouts/_partials/share_icons.html index 910ba7f1..dff6bbb3 100644 --- a/layouts/_partials/share_icons.html +++ b/layouts/_partials/share_icons.html @@ -1,12 +1,12 @@ {{- $pageurl := .Permalink }} {{- $title := .Title }} -{{- $.Scratch.Set "tags" ""}} +{{- $tags := ""}} {{- with .Params.Tags }} -{{- $hashtags := newScratch}} -{{- range . }}{{ $hashtags.Add "tags" (slice (replaceRE "(\\s)" "" . ))}}{{end}} -{{- $.Scratch.Set "tags" (delimit ($hashtags.Get "tags") ",") }} +{{- $hashtags := slice }} +{{- range . }}{{ $hashtags = $hashtags | append (replaceRE "(\\s)" "" . ) }}{{end}} +{{- $tags = delimit $hashtags "," }} {{- end -}} {{- $custom := false }} @@ -17,7 +17,7 @@ {{- if (or (cond ($custom) (in $ShareButtons "x") (true)) (cond ($custom) (in $ShareButtons "twitter") (true))) }}
  • + href="https://x.com/intent/tweet/?text={{ $title }}&url={{ $pageurl }}&hashtags={{- $tags -}}"> diff --git a/layouts/_partials/templates/schema_json.html b/layouts/_partials/templates/schema_json.html index e5250bfb..157c7289 100644 --- a/layouts/_partials/templates/schema_json.html +++ b/layouts/_partials/templates/schema_json.html @@ -26,7 +26,7 @@ {{- $lang_url := strings.TrimPrefix ( printf "%s/" .Lang) $url }} {{- $bc_list := (split $lang_url "/")}} -{{- $scratch := newScratch }} +{{- $path := "" }} {{- else }} diff --git a/layouts/_shortcodes/ltr.html b/layouts/_shortcodes/ltr.html index 4ad7682b..3434f2ab 100644 --- a/layouts/_shortcodes/ltr.html +++ b/layouts/_shortcodes/ltr.html @@ -1,13 +1,13 @@ -{{ $.Scratch.Set "md" false }} +{{ $md := false }} {{ if .IsNamedParams }} -{{ $.Scratch.Set "md" (.Get "md") }} +{{ $md = .Get "md" }} {{ else }} -{{ $.Scratch.Set "md" (.Get 0) }} +{{ $md = .Get 0 }} {{ end }}
    - {{ if eq ($.Scratch.Get "md") false }} + {{ if eq $md false }} {{ .Inner }} {{ else }} {{ .Inner | markdownify }} diff --git a/layouts/_shortcodes/rtl.html b/layouts/_shortcodes/rtl.html index a69b8ce8..f3d04efa 100644 --- a/layouts/_shortcodes/rtl.html +++ b/layouts/_shortcodes/rtl.html @@ -1,13 +1,13 @@ -{{ $.Scratch.Set "md" false }} +{{ $md := false }} {{ if .IsNamedParams }} -{{ $.Scratch.Set "md" (.Get "md") }} +{{ $md = .Get "md" }} {{ else }} -{{ $.Scratch.Set "md" (.Get 0) }} +{{ $md = .Get 0 }} {{ end }}
    - {{ if eq ($.Scratch.Get "md") false }} + {{ if eq $md false }} {{ .Inner }} {{ else }} {{ .Inner | markdownify }} diff --git a/layouts/index.json b/layouts/index.json index feeb437d..35f51143 100644 --- a/layouts/index.json +++ b/layouts/index.json @@ -1,7 +1,7 @@ -{{- $.Scratch.Add "index" slice -}} +{{- $index := slice -}} {{- range site.RegularPages -}} {{- if and (not .Params.searchHidden) (ne .Layout `archives`) (ne .Layout `search`) }} - {{- $.Scratch.Add "index" (dict "title" .Title "content" .Plain "permalink" .Permalink "summary" .Summary) -}} + {{- $index = $index | append (dict "title" .Title "content" .Plain "permalink" .Permalink "summary" .Summary) -}} {{- end }} {{- end -}} -{{- $.Scratch.Get "index" | jsonify -}} +{{- $index | jsonify -}}