Skip to content

Commit

Permalink
fix: chaos caused by unreset .Scratch
Browse files Browse the repository at this point in the history
  • Loading branch information
reuixiy committed Dec 7, 2019
1 parent d4edbff commit 3e862b4
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 3 deletions.
8 changes: 6 additions & 2 deletions layouts/_default/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@ <h1 class="list-title">{{ .Title | default .Data.Term | default (delimit (last 1
{{ end }}
{{ end }}

{{ .Scratch.Delete "pages" }}

<!-- Section -->
{{ if (eq .Kind "section") }}
<!-- Archives -->
{{ if (eq .Section "archives") }}
{{ $pages := (where .Site.RegularPages "Section" "in" .Site.Params.mainSections) }}
{{ $.Scratch.Set "pages" $pages }}
{{ .Scratch.Set "pages" $pages }}
<!-- Regular Section -->
{{ else }}
{{ $sectionPage := .CurrentSection }}
{{ .Scratch.Delete "pages" }}
{{ range .Site.RegularPages }}
{{ if (.IsDescendant $sectionPage) }}
{{ $.Scratch.Add "pages" (slice .) }}
Expand All @@ -46,11 +47,13 @@ <h1 class="list-title">{{ .Title | default .Data.Term | default (delimit (last 1
{{ $pages := .Scratch.Get "pages" }}
{{ range $pages.GroupByDate "2006" }}
<ul class="list-part">
{{ $.Scratch.Delete "zodiacName" }}
{{ if $.Site.Params.chineseZodiac }}
{{ $zodiacName := (index $.Site.Data.ChineseZodiac (string (mod .Key 12))) }}
{{ $.Scratch.Set "zodiacName" $zodiacName }}
{{ end }}
{{ $zodiacName := $.Scratch.Get "zodiacName" }}
{{ $.Scratch.Delete "year" }}
{{ if $.Site.Params.i18nYear }}
{{ $key := .Key }}
{{ $.Scratch.Delete "num" }}
Expand All @@ -71,6 +74,7 @@ <h1 class="list-title">{{ .Title | default .Data.Term | default (delimit (last 1
<h2 class="list-year">{{ $year }}{{ if $.Site.Params.chineseZodiac }}{{ replace (index $.Site.Data.SVG $zodiacName) "icon" "icon chinese-zodiac" | safeHTML }}{{ end }}</h2>
{{ if $.Site.Params.groupByMonth }}
{{ range .Pages.GroupByDate "January" }}
{{ $.Scratch.Delete "month" }}
{{ if $.Site.Params.i18nMonth }}
{{ $month := i18n (lower .Key) }}
{{ $.Scratch.Set "month" $month }}
Expand Down
1 change: 1 addition & 0 deletions layouts/partials/components/author.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- .Scratch.Delete "author" -}}
{{- if .Params.original | default .Site.Params.original -}}
{{- with .Site.Author.name -}}
{{- $.Scratch.SetInMap "author" "name" . -}}
Expand Down
1 change: 1 addition & 0 deletions layouts/partials/components/auto-detect-images.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
{{- with $imgs -}}
{{- $.Scratch.Delete "imgsURL" -}}
{{- range . -}}
{{- $.Scratch.Delete "replacement" -}}
{{- if and $.Site.Params.enableImageHost $.Site.Params.headAlso -}}
{{- if (eq hugo.Environment "production") -}}
{{- $url := replaceRE `<img src="/?([^"]+)` `$1` . -}}
Expand Down
4 changes: 4 additions & 0 deletions layouts/partials/components/data-attributes.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<!-- Small Caps -->
{{- .Scratch.Delete "smallCaps" -}}
{{- if .Params.smallCaps | default .Site.Params.enableSmallCaps -}}
{{- .Scratch.Set "smallCaps" true -}}
{{- end -}}

<!-- Align -->
{{- .Scratch.Delete "align" -}}
{{- with .Params.align | default "default" -}}
{{- if eq . "justify" -}}
{{- $.Scratch.Set "align" "justify" -}}
Expand All @@ -17,11 +19,13 @@
{{- end -}}

<!-- Type: poetry -->
{{- .Scratch.Delete "type" -}}
{{- if and (eq .Type "poetry") .IsPage -}}
{{- $.Scratch.Set "type" "poetry" -}}
{{- end -}}

<!-- Paragraph Indent -->
{{- .Scratch.Delete "indent" -}}
{{- if ne .Type "poetry" -}}
{{- if (and .Site.Params.enableParagraphIndent .Params.indent) | default (and .Site.Params.enableParagraphIndent (eq .Site.Params.paragraphStyle "indent")) -}}
{{- .Scratch.Set "indent" true -}}
Expand Down
2 changes: 2 additions & 0 deletions layouts/partials/components/date.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{{- $.Scratch.Delete "pubDate" -}}
{{- if .PublishDate.IsZero -}}
{{- $pubDate := dateFormat "2006-01-02T15:04:05-07:00" (time .Site.Params.siteCreatedTime) -}}
{{- $.Scratch.Set "pubDate" $pubDate -}}
{{- else -}}
{{- $pubDate := .PublishDate.Format "2006-01-02T15:04:05-07:00" -}}
{{- $.Scratch.Set "pubDate" $pubDate -}}
{{- end -}}
{{- $.Scratch.Delete "modDate" -}}
{{- if .Lastmod.IsZero -}}
{{- $modDate := dateFormat "2006-01-02T15:04:05-07:00" (time .Site.Params.siteCreatedTime) -}}
{{- $.Scratch.Set "modDate" $modDate -}}
Expand Down
2 changes: 1 addition & 1 deletion layouts/partials/components/keywords.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
{{- $.Scratch.Add "keywordsSite" (printf "%s, " .) -}}
{{- end -}}
<!-- keywordsPost -->
{{- $.Scratch.Delete "keywordsPost" -}}
{{- if .IsPage -}}
{{- $.Scratch.Delete "keywordsPost" -}}
{{- range $taxonomy, $terms := .Site.Taxonomies -}}
{{- with $.Param $taxonomy -}}
{{- range $index, $term := . -}}
Expand Down
1 change: 1 addition & 0 deletions layouts/partials/dark-mode.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
{{ $.Scratch.Set "text" "🌙" }}
{{ end }}
{{ $text := $.Scratch.Get "text" }}
{{- $.Scratch.Delete "hide" -}}
{{- if or (and $.IsHome $.Site.Params.hideThemeToggleInHome) (and (not $.IsHome) $.Site.Params.hideThemeToggle) -}}
{{- $.Scratch.Set "hide" true -}}
{{- end -}}
Expand Down
1 change: 1 addition & 0 deletions layouts/partials/minimal-footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
{{ with .Params.categories }}
<div class="post-category">
{{ if eq (len $.Site.Taxonomies.categories) 2 }}
{{- $.Scratch.Delete "categoryNow" -}}
{{- range . -}}
{{- $categoryNow := (. | urlize) -}}
{{- $.Scratch.Set "categoryNow" $categoryNow -}}
Expand Down
1 change: 1 addition & 0 deletions layouts/partials/multilingual.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{{ if and .Site.IsMultiLingual .Site.Params.enableLangToggle }}
{{- .Scratch.Delete "hide" -}}
{{- if .IsHome -}}
{{- if .Site.Params.hideLangToggleInHome -}}
{{- .Scratch.Set "hide" true -}}
Expand Down

0 comments on commit 3e862b4

Please sign in to comment.