Skip to content

Commit

Permalink
chore(search): use local scratch to collection index data, in order t…
Browse files Browse the repository at this point in the history
…o avoid conflicting with global variables
  • Loading branch information
razonyang committed Sep 19, 2022
1 parent ce758a2 commit 9232099
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions layouts/partials/search/index.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{{- $.Scratch.Add "pages" slice -}}
{{- $.Scratch.Add "authors" slice }}
{{- $.Scratch.Add "categories" slice }}
{{- $.Scratch.Add "series" slice }}
{{- $.Scratch.Add "tags" slice }}
{{- $scratch := newScratch -}}
{{- $scratch.Add "pages" slice -}}
{{- $scratch.Add "authors" slice }}
{{- $scratch.Add "categories" slice }}
{{- $scratch.Add "series" slice }}
{{- $scratch.Add "tags" slice }}
{{- range where .Site.AllPages "Kind" "page" -}}
{{- $page := . }}
{{- $date := .Date | time.Format ":date_long" -}}
Expand Down Expand Up @@ -45,20 +46,20 @@
{{- range $page.GetTerms $taxonomyName }}
{{- $terms = $terms | append (dict "title" .Title "url" .Permalink) }}
{{- $termTitles = $termTitles | append .Title }}
{{- $.Scratch.Add ($taxonomyName | pluralize) (slice .Title) }}
{{- $scratch.Add ($taxonomyName | pluralize) (slice .Title) }}
{{- end }}
{{- $item = merge $item (dict
$taxonomyName $terms
(printf "%s_titles" $taxonomyName) (delimit $termTitles " ")
)}}
{{- end }}
{{- $.Scratch.Add "pages" (slice $item) }}
{{- $scratch.Add "pages" (slice $item) }}
{{- end -}}
{{- dict
"pages" ($.Scratch.Get "pages")
"authors" ($.Scratch.Get "authors"| uniq)
"categories" ($.Scratch.Get "categories"| uniq)
"series" ($.Scratch.Get "series" | uniq)
"tags" ($.Scratch.Get "tags"| uniq)
"pages" ($scratch.Get "pages")
"authors" ($scratch.Get "authors" | uniq)
"categories" ($scratch.Get "categories" | uniq)
"series" ($scratch.Get "series" | uniq)
"tags" ($scratch.Get "tags"| uniq)
| jsonify
-}}

0 comments on commit 9232099

Please sign in to comment.