♻️ Refactor: global/site/page scope state management (#610)

*  Perf: adjust global/site scope state management

*  Perf: adjust page scope state management
This commit is contained in:
Cell
2025-07-03 12:34:28 +08:00
parent d9043280fe
commit 3e8bdfd8f9
42 changed files with 165 additions and 173 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
{{- $analytics := .Scratch.Get "analytics" | default dict -}}
{{- $analytics := .Site.Store.Get "analytics" | default dict -}}
{{- if $analytics.enable -}}
{{- /* Google Analytics */ -}}
+4 -4
View File
@@ -1,6 +1,6 @@
{{- $compatibility := .Site.Params.compatibility | default dict -}}
{{- $cdn := .Scratch.Get "cdn" | default dict -}}
{{- $fingerprint := .Scratch.Get "fingerprint" -}}
{{- $cdn := .Site.Store.Get "cdn" | default dict -}}
{{- $fingerprint := .Site.Store.Get "fingerprint" -}}
{{- /* Polyfill.io */ -}}
{{- if $compatibility.polyfill -}}
@@ -11,12 +11,12 @@
{{- end -}}
{{- end -}}
{{- with $features | uniq -}}
{{- delimit . "%2C" | printf "https://cdnjs.cloudflare.com/polyfill/v3/polyfill.js?features=%v" | dict "Source" | dict "Scratch" $.Scratch "Data" | partial "scratch/script.html" -}}
{{- delimit . "%2C" | printf "https://cdnjs.cloudflare.com/polyfill/v3/polyfill.js?features=%v" | dict "Source" | dict "Page" $ "Data" | partial "scratch/script.html" -}}
{{- end -}}
{{- end -}}
{{- /* object-fit-images */ -}}
{{- if $compatibility.objectFit -}}
{{- $source := $cdn.objectFitImagesJS | default "lib/object-fit-images/ofi.min.js" -}}
{{- dict "Source" $source "Fingerprint" $fingerprint | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}}
{{- dict "Source" $source "Fingerprint" $fingerprint | dict "Page" . "Data" | partial "scratch/script.html" -}}
{{- end -}}
@@ -7,7 +7,7 @@
{{- $loading := resources.Get "images/loading.svg" | minify -}}
{{- $id := "fixit-decryptor-input" -}}
{{- if .IsPartial -}}
{{- $id = dict "Scratch" page.Scratch | partial "function/id.html" -}}
{{- $id = dict "Page" .Page | partial "function/id.html" -}}
{{- end -}}
<fixit-encryptor>
<div class="fixit-decryptor-container">
+4 -4
View File
@@ -21,13 +21,13 @@
{{- if $enable | and $key -}}
{{- $configJS := "" -}}
{{- $fingerprint := .Scratch.Get "fingerprint" -}}
{{- $fingerprint := .Site.Store.Get "fingerprint" -}}
{{- $sourceOpts := dict "Fingerprint" $fingerprint "Defer" true -}}
{{- /* PostSummary */ -}}
{{- if $summaryEnable -}}
{{- $postChatCSS := "https://ai.zhheo.com/static/public/postChatUser_summary.min.css" -}}
{{- dict "Source" $postChatCSS "Fingerprint" $fingerprint | dict "Scratch" .Scratch "Data" | partial "scratch/style.html" -}}
{{- dict "Source" $postChatCSS "Fingerprint" $fingerprint | dict "Page" . "Data" | partial "scratch/style.html" -}}
{{- $p := "tianliGPT" -}}
{{- $postSummaryConfig := printf "let %v_postSelector='#content';" $p -}}
{{- with $summaryConfig.title -}}
@@ -100,7 +100,7 @@
{{- end -}}
{{- /* Insert config */ -}}
{{- $configJS | dict "Content" | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}}
{{- $configJS | dict "Content" | dict "Page" . "Data" | partial "scratch/script.html" -}}
{{- /* Insert script */ -}}
{{- $postChatJS := "" -}}
@@ -112,5 +112,5 @@
{{- $postChatJS = add $sourcePrefix (index $jsMap "summary") -}}
{{- end -}}
{{- $sourceOpts = dict "Source" $postChatJS | merge $sourceOpts -}}
{{- $sourceOpts | dict "Scratch" $.Scratch "Data" | partial "scratch/script.html" -}}
{{- $sourceOpts | dict "Page" . "Data" | partial "scratch/script.html" -}}
{{- end -}}
+4 -4
View File
@@ -89,14 +89,14 @@
{{- /* 013: Line */ -}}
{{- if $share.Line -}}
<a href="javascript:void(0);" title="{{ T `shareOn` }} Line" data-sharer="line" data-url="{{ .Permalink }}" data-title="{{ $title }}">
{{- dict "Simpleicons" "line" "Prefix" (.Scratch.Get "cdn" | default dict).simpleIconsPrefix | partial "plugin/icon.html" -}}
{{- dict "Simpleicons" "line" "Prefix" (.Site.Store.Get "cdn" | default dict).simpleIconsPrefix | partial "plugin/icon.html" -}}
</a>
{{ end -}}
{{- /* 014: Instapaper */ -}}
{{- if $share.Instapaper -}}
<a href="javascript:void(0);" title="{{ T `shareOn` }} Instapaper" data-sharer="instapaper" data-url="{{ .Permalink }}" data-title="{{ $title }}" data-description="{{ .Description }}">
{{- dict "Simpleicons" "instapaper" "Prefix" (.Scratch.Get "cdn" | default dict).simpleIconsPrefix | partial "plugin/icon.html" -}}
{{- dict "Simpleicons" "instapaper" "Prefix" (.Site.Store.Get "cdn" | default dict).simpleIconsPrefix | partial "plugin/icon.html" -}}
</a>
{{ end -}}
@@ -133,7 +133,7 @@
{{- /* 021: Myspace */ -}}
{{- if $share.Myspace -}}
<a href="javascript:void(0);" title="{{ T `shareOn` }} Myspace" data-sharer="myspace" data-url="{{ .Permalink }}" data-title="{{ $title }}" data-description="{{ .Description }}">
{{- dict "Simpleicons" "myspace" "Prefix" (.Scratch.Get "cdn" | default dict).simpleIconsPrefix | partial "plugin/icon.html" -}}
{{- dict "Simpleicons" "myspace" "Prefix" (.Site.Store.Get "cdn" | default dict).simpleIconsPrefix | partial "plugin/icon.html" -}}
</a>
{{ end -}}
@@ -147,7 +147,7 @@
{{- /* 023: 百度 */ -}}
{{- if $share.Baidu -}}
<a href="javascript:void(0);" title="{{ T `shareOn` }} 百度" data-sharer="baidu" data-url="{{ .Permalink }}" data-title="{{ $title }}">
{{- dict "Simpleicons" "baidu" "Prefix" (.Scratch.Get "cdn" | default dict).simpleIconsPrefix | partial "plugin/icon.html" -}}
{{- dict "Simpleicons" "baidu" "Prefix" (.Site.Store.Get "cdn" | default dict).simpleIconsPrefix | partial "plugin/icon.html" -}}
</a>
{{ end -}}