hugo-theme-learn icon indicating copy to clipboard operation
hugo-theme-learn copied to clipboard

Search Results

Open patriotaki opened this issue 6 years ago • 2 comments

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 -}}]```

patriotaki avatar Feb 07 '20 16:02 patriotaki

bump?

patriotaki avatar Feb 10 '20 19:02 patriotaki

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 -}}]

McShelby avatar Sep 13 '20 15:09 McShelby