allow custom searchable fields
Signed-off-by: weru <fromweru@gmail.com>
| | |
| | | function initializeSearch(index) { |
| | | const searchKeys = ['title', 'link', 'body', 'id', 'section', 'tags']; |
| | | let searchKeys = ['title', 'id', 'link', 'body', 'section']; |
| | | searchKeys = searchKeys.concat(otherSearchableFields); |
| | | |
| | | console.log(searchKeys); |
| | | |
| | | const searchPageElement = elem('#searchpage'); |
| | | |
| | |
| | | includeScore: true, |
| | | shouldSort: true, |
| | | keys: searchKeys, |
| | | threshold: 0.0 |
| | | threshold: 0.5 |
| | | }; |
| | | |
| | | index = new Fuse(index, searchOptions); |
| | |
| | | const codeBlockConfig = JSON.parse('{{ partial "functions/getCodeConfig" . }}'); |
| | | const iconsPath = `{{ partialCached "functions/getIconPath" . }}`; |
| | | |
| | | // values defined under config/_default/params.toml |
| | | let otherSearchableFields = '{{ delimit (default slice site.Params.otherSearchableFields) ", " }}' |
| | | |
| | | if(otherSearchableFields.length > 2) { |
| | | otherSearchableFields = otherSearchableFields |
| | | .split(",") |
| | | .map(search_value => search_value.toLowerCase().trim()); |
| | | } else { |
| | | otherSearchableFields = []; |
| | | } |
| | | |
| | | console.log(otherSearchableFields); |
| | | |
| | | // defined in i18n / translation files |
| | | const quickLinks = '{{ T "quick_links" }}'; |
| | | const searchResultsLabel = '{{ T "search_results_label" }}'; |
| | |
| | | # By default the template will look for icons under the icons directory. In some situations you might wanna change that. edit the line below |
| | | # iconsPath = 'icons/' |
| | | |
| | | otherSearchableFields = ["Tags", "Categories", "CustomField"] # As they appear in frontmatter |
| | | |
| | | # Site logo |
| | | [logo] |
| | | lightMode = "images/compose.svg" |
| | |
| | | {{- $.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")) -}} |