Skip to content

Commit

Permalink
🐛 Fix: to create a scratch pad that is not reset on server rebuilds, …
Browse files Browse the repository at this point in the history
…use the Store method instead of Scratch method (fixes #417)
  • Loading branch information
Lruihao committed Feb 23, 2024
1 parent 002ebda commit b2b4709
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 39 deletions.
2 changes: 1 addition & 1 deletion layouts/_default/single.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{- $params := .Scratch.Get "params" -}}
{{- $author := .Scratch.Get "author" -}}
{{- $author := .Store.Get "author" -}}
# {{ .Title }}

{{ if $params.password -}}
Expand Down
30 changes: 0 additions & 30 deletions layouts/partials/init/patch.html
Original file line number Diff line number Diff line change
@@ -1,36 +1,6 @@
{{- /* FixIt theme patches */ -}}
{{- $params := .Scratch.Get "params" -}}

{{- /* Author data patch */ -}}
{{- $authorDefault := dict "name" "Anonymous" "link" "" "email" "" "avatar" "" -}}
{{- $author := .Site.Params.author | merge $authorDefault -}}
{{- $authorPost := dict -}}
{{- $gravatar := .Site.Params.gravatar -}}
{{- if reflect.IsMap $params.author -}}
{{- $authorPost = $params.author -}}
{{- else if isset $params "author" -}}
{{- $authorPost = dict "name" $params.author -}}
{{- end -}}
{{- if isset $authorPost "name" | and (ne $authorPost.name .Site.Params.author.name) -}}
{{- $author = $authorPost | merge $authorDefault | merge $author -}}
{{- else -}}
{{- with $authorPost.link -}}{{ $author = dict "link" . | merge $author }}{{- end -}}
{{- with $authorPost.email -}}{{ $author = dict "email" . | merge $author }}{{- end -}}
{{- with $authorPost.avatar -}}{{ $author = dict "avatar" . | merge $author }}{{- end -}}
{{- end -}}

{{- if $gravatar.enable | and $author.email -}}
{{- with $gravatar -}}
{{- $author = dict "avatar" (printf "https://%v/avatar/%v?s=32&d=%v"
(path.Clean .Host | default "www.gravatar.com")
(md5 $author.email)
(.Style | default ""))
| merge $author
-}}
{{- end -}}
{{- end -}}
{{- .Scratch.Set "author" $author -}}

{{- /* Toc data patch */ -}}
{{- $toc := $params.toc -}}
{{- if eq $toc true -}}
Expand Down
8 changes: 6 additions & 2 deletions layouts/partials/plugin/reward.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{- $reward := .Reward -}}
{{- $id := .Id -}}
{{- $author := .Author -}}
{{- $author := .Author | default "" -}}

{{- if $reward.enable -}}
<div class="post-reward">
Expand All @@ -12,7 +12,11 @@
{{- with T (printf "single.reward.%v" $way) -}}{{ $way = . }}{{- end -}}
{{- if $image -}}
<div>
{{- dict "Src" $image "Alt" (printf "%v %v" $author $way) | partial "plugin/image.html" -}}
{{-
dict "Src" $image
"Alt" (strings.TrimPrefix " " (printf "%v %v" $author $way))
| partial "plugin/image.html"
-}}
<span{{ if $reward.animation }} data-animation{{ end }}>{{ $way }}</span>
</div>
{{- end -}}
Expand Down
38 changes: 34 additions & 4 deletions layouts/partials/single/post-author.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,41 @@
{{- $params := .Scratch.Get "params" -}}
{{- $author := .Scratch.Get "author" -}}
{{- $params := .Params | merge .Site.Params.page -}}

{{- /* Author data patch */ -}}
{{- $authorDefault := dict "name" "" "link" "" "email" "" "avatar" "" -}}
{{- $author := .Site.Params.author | merge $authorDefault -}}
{{- $authorPost := dict -}}
{{- if reflect.IsMap $params.author -}}
{{- $authorPost = $params.author -}}
{{- else if isset $params "author" -}}
{{- warnf "检测到你的 author 参数格式错误,请参考主题文档设置为正常的格式。" -}}
{{- $authorPost = dict "name" $params.author -}}
{{- end -}}
{{- if isset $authorPost "name" | and (ne $authorPost.name .Site.Params.author.name) -}}
{{- $author = $authorPost | merge $authorDefault | merge $author -}}
{{- else -}}
{{- with $authorPost.link -}}{{ $author = dict "link" . | merge $author }}{{- end -}}
{{- with $authorPost.email -}}{{ $author = dict "email" . | merge $author }}{{- end -}}
{{- with $authorPost.avatar -}}{{ $author = dict "avatar" . | merge $author }}{{- end -}}
{{- end -}}

{{- $gravatar := .Site.Params.gravatar -}}
{{- if $gravatar.enable | and $author.email -}}
{{- with $gravatar -}}
{{- $author = dict "avatar" (printf "https://%v/avatar/%v?s=32&d=%v"
(path.Clean .Host | default "www.gravatar.com")
(md5 $author.email)
(.Style | default ""))
| merge $author
-}}
{{- end -}}
{{- end -}}
{{- .Store.Set "author" $author -}}

<span class="post-author">
{{- $content := $author.name -}}
{{- $content := $author.name | default "Anonymous" -}}
{{- $icon := dict "Class" "fa-solid fa-user-circle" -}}
{{- if $author.avatar | and $params.authorAvatar -}}
{{- $content = printf "%v&nbsp;%v" (dict "Src" $author.avatar "Class" "avatar" "Alt" $author.name | partial "plugin/image.html") $author.name -}}
{{- $content = printf "%v&nbsp;%v" (dict "Src" $author.avatar "Class" "avatar" "Alt" $content | partial "plugin/image.html") $content -}}
{{- $icon = "" -}}
{{- end -}}
{{- if $author.link -}}
Expand Down
2 changes: 1 addition & 1 deletion layouts/partials/single/reward.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- $reward := .Scratch.Get "reward" -}}
{{- $author := .Scratch.Get "author" -}}
{{- $author := .Store.Get "author" -}}
{{- $options := dict "Reward" $reward "Id" "fi-reward" "Author" $author.name -}}
{{- partial "plugin/reward.html" $options -}}
2 changes: 1 addition & 1 deletion layouts/shortcodes/reward.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{{- $alipay := (.Get "alipay") | default (.Get 1) -}}
{{- $paypal := (.Get "paypal") | default (.Get 2) -}}
{{- $bitcoin := (.Get "bitcoin") | default (.Get 3) -}}
{{- $author := (.Get "author") | default (.Get 4) | default (.Page.Scratch.Get "author").name -}}
{{- $author := (.Get "author") | default (.Get 4) -}}
{{- $comment := (.Get "comment") | default (.Get 5) -}}
{{- $mode := (.Get "mode") | default (.Get 6) -}}
{{- $reward := dict "enable" true "comment" $comment "mode" $mode -}}
Expand Down

0 comments on commit b2b4709

Please sign in to comment.