2019-10-27 11:58:58 +01:00
|
|
|
'use strict';
|
|
|
|
|
2020-07-06 22:17:36 +02:00
|
|
|
(function () {
|
2020-01-13 19:42:16 +01:00
|
|
|
const indexCfg = {{ with i18n "bookSearchConfig" }}
|
2019-11-10 14:35:07 +01:00
|
|
|
{{ . }};
|
|
|
|
{{ else }}
|
|
|
|
{};
|
|
|
|
{{ end }}
|
2019-07-16 14:34:02 +02:00
|
|
|
|
2019-10-27 11:58:58 +01:00
|
|
|
indexCfg.doc = {
|
|
|
|
id: 'id',
|
|
|
|
field: ['title', 'content'],
|
2020-07-06 22:17:36 +02:00
|
|
|
store: ['title', 'href', 'section'],
|
2019-10-27 11:58:58 +01:00
|
|
|
};
|
2019-10-20 19:02:32 +02:00
|
|
|
|
2019-10-27 11:58:58 +01:00
|
|
|
const index = FlexSearch.create('balance', indexCfg);
|
|
|
|
window.bookSearchIndex = index;
|
2019-10-20 19:02:32 +02:00
|
|
|
|
2020-09-15 00:17:28 +02:00
|
|
|
{{- $pages := where .Site.Pages "Kind" "in" (slice "page" "section") -}}
|
|
|
|
{{- $pages = where $pages "Params.booksearchexclude" "!=" true -}}
|
|
|
|
{{- $pages = where $pages "Content" "not in" (slice nil "") -}}
|
|
|
|
|
|
|
|
{{ range $index, $page := $pages }}
|
2019-10-27 11:58:58 +01:00
|
|
|
index.add({
|
|
|
|
'id': {{ $index }},
|
|
|
|
'href': '{{ $page.RelPermalink }}',
|
|
|
|
'title': {{ (partial "docs/title" $page) | jsonify }},
|
2020-07-06 22:17:36 +02:00
|
|
|
'section': {{ (partial "docs/title" $page.Parent) | jsonify }},
|
2019-10-27 11:58:58 +01:00
|
|
|
'content': {{ $page.Plain | jsonify }}
|
|
|
|
});
|
|
|
|
{{- end -}}
|
2019-07-16 14:34:02 +02:00
|
|
|
})();
|