Skip to content

Commit

Permalink
feat: generate the hash for search indices (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
razonyang authored May 13, 2023
1 parent 6cf9542 commit 03db352
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
3 changes: 2 additions & 1 deletion layouts/_default/index.searchindex.json
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
{{- partial "search/index.json" . -}}
{{- $ctx := dict "Site" .Site }}
{{- partialCached "search/index.json" $ctx $ctx -}}
5 changes: 4 additions & 1 deletion layouts/partials/search/assets/js-resource.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,11 @@
{{/* Index files URL. */}}
{{- $indices := slice }}
{{- range .Sites }}
{{- $site := . }}
{{- with .Home.OutputFormats.Get "SearchIndex" }}
{{- $indices = $indices | append .RelPermalink }}
{{- $idxCtx := dict "Site" $site "Index" . }}
{{- $indexURL := partialCached "search/functions/search-index-url" $idxCtx $idxCtx }}
{{- $indices = $indices | append $indexURL }}
{{- end }}
{{- end }}
{{- $defaultParams := partialCached "search/functions/params" . }}
Expand Down
3 changes: 3 additions & 0 deletions layouts/partials/search/functions/search-index-url.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{- $ctx := dict "Site" .Site }}
{{- $hash := partialCached "search/index.json" $ctx $ctx | md5 }}
{{- return (printf "%s?v=%s" .Index.RelPermalink $hash) }}

0 comments on commit 03db352

Please sign in to comment.