From bba9312386885a39ef8b1131c21cdd76d6574bf1 Mon Sep 17 00:00:00 2001
From: weru <fromweru@gmail.com>
Date: Thu, 29 Dec 2022 20:35:18 +0000
Subject: [PATCH] allow custom searchable fields
---
layouts/_default/index.json | 19 +++++++++++++++++--
1 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/layouts/_default/index.json b/layouts/_default/index.json
index 34e9dc3..7f15558 100644
--- a/layouts/_default/index.json
+++ b/layouts/_default/index.json
@@ -1,7 +1,22 @@
{{- $.Scratch.Add "index" slice -}}
-{{- range .Site.Pages -}}
+{{- $searchableExtras := site.Params.otherSearchableFields }}
+{{- range site.Pages -}}
+ {{ $params := .Params }}
{{- if ne .Type "search" -}}
- {{- $.Scratch.Add "index" (dict "title" .Title "body" .Plain "link" .Permalink "section" .Section) -}}
+ {{- $searchEntry := dict "title" .Title "body" .Plain "link" .Permalink "section" .Section }}
+ {{- range $index, $value := $searchableExtras }}
+ {{- $extraFieldValue := index $params $value }}
+ {{- $extraFieldValues := dict }}
+ {{- with $extraFieldValue }}
+ {{- $v := . }}
+ {{- if reflect.IsSlice . }}
+ {{- $v = delimit . "," }}
+ {{- end }}
+ {{- $extraFieldValues = dict (lower $value) $v }}
+ {{- end }}
+ {{- $searchEntry = merge $searchEntry $extraFieldValues }}
+ {{- end }}
+ {{- $.Scratch.Add "index" $searchEntry -}}
{{- end -}}
{{- end -}}
{{- jsonify (uniq ($.Scratch.Get "index")) -}}
\ No newline at end of file
--
Gitblit v1.10.0