From 8258461171483105400a77499d855251a2d205fb Mon Sep 17 00:00:00 2001 From: Travis Beckham Date: Wed, 5 Jun 2024 10:04:14 -0500 Subject: [PATCH] Improved performance and readability of search index (#1783) * Improved search index Signed-off-by: Travis Beckham * Added page variable to Ancestors range for consistency Signed-off-by: Travis Beckham * Added comments Signed-off-by: Travis Beckham --- linkerd.io/layouts/index.searchindex.json | 36 +++++++++++++---------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/linkerd.io/layouts/index.searchindex.json b/linkerd.io/layouts/index.searchindex.json index 6c30b1df9b..af5a3b9ec2 100644 --- a/linkerd.io/layouts/index.searchindex.json +++ b/linkerd.io/layouts/index.searchindex.json @@ -1,18 +1,22 @@ +{{- /* Ouput a json search index of all docs in the 2.15 section */ -}} {{- $pages := where site.Pages "Section" "eq" "2.15" -}} -[ - {{- range $index, $page := $pages -}} - {{- if gt $index 0 -}} , {{- end -}} - {{- $ancestors := slice "linkerd.io" -}} - {{- range .Ancestors.Reverse -}} - {{- if .IsHome }}{{ continue }}{{ end -}} - {{- $ancestors = $ancestors | append .Title -}} - {{- end -}} - {{- $entry := dict "uri" $page.Permalink -}} - {{- $entry = merge $entry (dict "title" $page.Title) -}} - {{- $entry = merge $entry (dict "ancestors" $ancestors) -}} - {{- $entry = merge $entry (dict "content" ($page.Plain | htmlUnescape | truncate 3000)) -}} - {{- $entry = merge $entry (dict "description" $page.Description) -}} - {{- $entry = merge $entry (dict "keywords" $page.Keywords) -}} - {{- $entry | jsonify -}} +{{- $.Scratch.Add "search-index" slice -}} +{{- range $index, $page := $pages -}} + {{- $ancestors := slice "linkerd.io" -}} + {{- range $page.Ancestors.Reverse -}} + {{- if .IsHome }}{{ continue }}{{ end -}} + {{- $ancestors = $ancestors | append .Title -}} {{- end -}} -] + {{- $.Scratch.Add + "search-index" + (dict + "uri" $page.Permalink + "title" $page.Title + "ancestors" $ancestors + "content" ($page.Plain | htmlUnescape | truncate 3000) + "description" $page.Description + "keywords" $page.Keywords + ) + -}} +{{- end -}} +{{- $.Scratch.Get "search-index" | jsonify -}}