Skip to content

Commit

Permalink
fix: correct indices URLs for multihost (#190)
Browse files Browse the repository at this point in the history
  • Loading branch information
razonyang committed Feb 1, 2024
1 parent bcc9ccb commit ec12c52
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 10 deletions.
3 changes: 1 addition & 2 deletions layouts/_default/index.searchindex.json
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
{{- $ctx := dict "Site" .Site }}
{{- partialCached "search/index.json" $ctx $ctx -}}
{{- partialCached "search/index.json" . -}}
3 changes: 2 additions & 1 deletion layouts/partials/search/assets/js-resource.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{{- $defaultLang := .Sites.First.Language.Lang }}
{{- $multihost := partialCached "search/functions/is-multihost" . }}
{{- $langs := newScratch }}
{{- range .Site.Languages }}
{{- $langs.Set .Lang (dict "lang" .Lang "name" .LanguageName) }}
Expand Down Expand Up @@ -79,7 +80,7 @@
{{- $site := . }}
{{- with .Home.OutputFormats.Get "SearchIndex" }}
{{- $hash := partialCached "search/functions/search-index-hash" $site $site }}
{{- $indexURL := printf "%s?v=%s" .RelPermalink $hash }}
{{- $indexURL := printf "%s?v=%s" (cond $multihost .Permalink .RelPermalink) $hash }}
{{- $indices = $indices | append $indexURL }}
{{- end }}
{{- end }}
Expand Down
11 changes: 11 additions & 0 deletions layouts/partials/search/functions/is-multihost.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{{- $v := false -}}
{{- $host := "" }}
{{- range site.Sites -}}
{{- $url := urls.Parse .Home.Permalink -}}
{{- if and (ne $host "") (ne $url.Host "") (ne $host $url.Host) -}}
{{- $v = true -}}
{{- break -}}
{{- end -}}
{{- $host = $url.Host -}}
{{- end -}}
{{- return $v -}}
4 changes: 2 additions & 2 deletions layouts/partials/search/functions/pages.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- $indexAllPages := default true .Site.Params.search.index_all_pages -}}
{{- $pages := cond $indexAllPages .Site.Pages .Site.RegularPages -}}
{{- $indexAllPages := default true site.Params.search.index_all_pages -}}
{{- $pages := cond $indexAllPages site.Pages site.RegularPages -}}
{{- $pages = where $pages "Params.noindex" "ne" true -}}
{{- return $pages }}
10 changes: 5 additions & 5 deletions layouts/partials/search/index.json.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{{- $items := slice -}}
{{- $indexContent := default false .Site.Params.search.index_content -}}
{{- $multihost := partialCached "search/functions/is-multihost" . }}
{{- $indexContent := default false site.Params.search.index_content -}}
{{- $years := true }}
{{- $pagesCtx := dict "Site" .Site }}
{{- $pages := partialCached "search/functions/pages" $pagesCtx .Site.Language.Lang -}}
{{- $pages := partial "search/functions/pages" . -}}
{{- range $pages -}}
{{- $page := . -}}
{{- $item := newScratch -}}
Expand All @@ -13,14 +13,14 @@
{{- end }}
{{- $item.Set "kind" .Kind -}}
{{- $item.Set "lang" .Language.Lang -}}
{{- $item.Set "url" .RelPermalink -}}
{{- $item.Set "url" (cond $multihost .Permalink .RelPermalink) -}}
{{- $item.Set "date" .Date.Unix -}}
{{- if $years }}
{{- $item.Set "year" (.Date.Format "2006") }}
{{- end }}
{{- $item.Set "headings" (partialCached "search/functions/parse-headings" . .) -}}
{{/* Taxonomies */}}
{{- range $name, $taxonomy := $.Site.Taxonomies -}}
{{- range $name, $taxonomy := site.Taxonomies -}}
{{- range $page.GetTerms $name -}}
{{- $item.Add $name (slice .Title) }}
{{- end -}}
Expand Down

0 comments on commit ec12c52

Please sign in to comment.