#236, #171 Add section to search results

This commit is contained in:
Alex Shpak
2020-07-06 22:17:36 +02:00
parent 05c6336d22
commit f416a71bf8
5 changed files with 29 additions and 9 deletions
+5 -2
View File
@@ -1,6 +1,6 @@
'use strict';
(function() {
(function () {
const indexCfg = {{ with i18n "bookSearchConfig" }}
{{ . }};
{{ else }}
@@ -10,18 +10,21 @@
indexCfg.doc = {
id: 'id',
field: ['title', 'content'],
store: ['title', 'href'],
store: ['title', 'href', 'section'],
};
const index = FlexSearch.create('balance', indexCfg);
window.bookSearchIndex = index;
{{ range $index, $page := where .Site.Pages "Kind" "in" (slice "page" "section") }}
{{ if $page.Content }}
index.add({
'id': {{ $index }},
'href': '{{ $page.RelPermalink }}',
'title': {{ (partial "docs/title" $page) | jsonify }},
'section': {{ (partial "docs/title" $page.Parent) | jsonify }},
'content': {{ $page.Plain | jsonify }}
});
{{- end -}}
{{- end -}}
})();