From 98cc7904abebb975332de6ecd8df1bef3a51d8b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Weber?= Date: Fri, 19 May 2023 11:09:05 +0200 Subject: [PATCH] tags: improve search index for tags #531 --- layouts/_default/index.json | 21 +++++++++++++++++---- layouts/_default/index.search.js | 19 ++++++++++++++++--- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/layouts/_default/index.json b/layouts/_default/index.json index b1a57ba196..bcd1472585 100644 --- a/layouts/_default/index.json +++ b/layouts/_default/index.json @@ -1,8 +1,21 @@ {{- partialCached "page-meta.hugo" . .RelPermalink }} {{- $pages := slice }} {{- range .Site.Pages }} -{{- if and .Title (or (ne (.Scratch.Get "relearnIsHiddenStem") true) (ne .Site.Params.disableSearchHiddenPages true) ) }} -{{- $pages = $pages | append (dict "uri" (partial "relLangPrettyUglyURL.hugo" (dict "to" .)) "title" .Title "tags" .Params.tags "description" .Description "content" (.Plain | htmlUnescape)) }} -{{- end }} -{{- end }} + {{- if and .Title (or (ne (.Scratch.Get "relearnIsHiddenStem") true) (ne .Site.Params.disableSearchHiddenPages true) ) }} + {{- $title := .Title }} + {{- if eq .Kind "taxonomy" }} + {{- $title = i18n .Data.Plural }} + {{- if not $title }} + {{- $title = .Data.Plural | humanize }} + {{- end }} + {{- else if eq .Kind "term" }} + {{- $title = i18n .Data.Singular }} + {{- if not $title }} + {{- $title = .Data.Singular | humanize }} + {{- end }} + {{- $title = printf "%s %s %s" $title (default "::" .Site.Params.titleSeparator) (.Title | humanize) }} + {{- end }} + {{- $pages = $pages | append (dict "uri" (partial "relLangPrettyUglyURL.hugo" (dict "to" .)) "title" $title "tags" .Params.tags "description" .Description "content" (.Plain | htmlUnescape)) }} + {{- end }} +{{- end -}} {{- $pages | jsonify (dict "indent" " ") }} diff --git a/layouts/_default/index.search.js b/layouts/_default/index.search.js index e4703b33d3..582e788fb7 100644 --- a/layouts/_default/index.search.js +++ b/layouts/_default/index.search.js @@ -1,8 +1,21 @@ {{- partialCached "page-meta.hugo" . .RelPermalink }} {{- $pages := slice }} {{- range .Site.Pages }} -{{- if and .Title (or (ne (.Scratch.Get "relearnIsHiddenStem") true) (ne .Site.Params.disableSearchHiddenPages true) ) }} -{{- $pages = $pages | append (dict "uri" (partial "relLangPrettyUglyURL.hugo" (dict "to" .)) "title" .Title "tags" .Params.tags "description" .Description "content" (.Plain | htmlUnescape)) }} -{{- end }} + {{- if and .Title (or (ne (.Scratch.Get "relearnIsHiddenStem") true) (ne .Site.Params.disableSearchHiddenPages true) ) }} + {{- $title := .Title }} + {{- if eq .Kind "taxonomy" }} + {{- $title = i18n .Data.Plural }} + {{- if not $title }} + {{- $title = .Data.Plural | humanize }} + {{- end }} + {{- else if eq .Kind "term" }} + {{- $title = i18n .Data.Singular }} + {{- if not $title }} + {{- $title = .Data.Singular | humanize }} + {{- end }} + {{- $title = printf "%s %s %s" $title (default "::" .Site.Params.titleSeparator) (.Title | humanize) }} + {{- end }} + {{- $pages = $pages | append (dict "uri" (partial "relLangPrettyUglyURL.hugo" (dict "to" .)) "title" $title "tags" .Params.tags "description" .Description "content" (.Plain | htmlUnescape)) }} + {{- end }} {{- end -}} var relearn_search_index = {{ $pages | jsonify (dict "indent" " ") }}