hugo-theme-learn
hugo-theme-learn copied to clipboard
Search Results
Hi all this is my index.json in /layouts/
I dont want to index the content of each page, only the tittle,description and tags should be searchable. If i remove the last link with the content search functionality stops working.
{{- if ne $page.Type "json" -}}
{{- if and $index (gt $index 0) -}},{{- end }}
{
"uri": "{{ $page.Permalink }}",
"title": "{{ htmlEscape $page.Title}}",
"tags": [{{ range $tindex, $tag := $page.Params.tags }}{{ if $tindex }}, {{ end }}"{{ $tag| htmlEscape }}"{{ end }}],
"description": "{{ htmlEscape .Description}}",
"content": {{$page.Plain | jsonify}}
}
{{- end -}}
{{- end -}}]```
bump?
I am not a specialist for search or lunr, but it seems search.js references this field. Not sure, but that might make it mandatory for index.json. A simple solution is to just set content empty:
[{{ range $index, $page := .Site.Pages }}
{{- if ne $page.Type "json" -}}
{{- if and $index (gt $index 0) -}},{{- end }}
{
"uri": "{{ $page.Permalink }}",
"title": "{{ htmlEscape $page.Title}}",
"tags": [{{ range $tindex, $tag := $page.Params.tags }}{{ if $tindex }}, {{ end }}"{{ $tag| htmlEscape }}"{{ end }}],
"description": "{{ htmlEscape .Description}}",
"content": ""
}
{{- end -}}
{{- end -}}]