hugo-book/assets/search-data.js

31 lines
733 B
JavaScript
Raw Normal View History

2019-10-27 10:58:58 +00:00
'use strict';
(function () {
const indexCfg = {{ with i18n "bookSearchConfig" }}
{{ . }};
{{ else }}
{};
{{ end }}
2019-07-16 12:34:02 +00:00
2019-10-27 10:58:58 +00:00
indexCfg.doc = {
id: 'id',
field: ['title', 'content'],
store: ['title', 'href', 'section'],
2019-10-27 10:58:58 +00:00
};
2019-10-20 17:02:32 +00:00
2019-10-27 10:58:58 +00:00
const index = FlexSearch.create('balance', indexCfg);
window.bookSearchIndex = index;
2019-10-20 17:02:32 +00:00
2020-03-12 09:58:52 +00:00
{{ range $index, $page := where .Site.Pages "Kind" "in" (slice "page" "section") }}
{{ if $page.Content }}
2019-10-27 10:58:58 +00:00
index.add({
'id': {{ $index }},
'href': '{{ $page.RelPermalink }}',
'title': {{ (partial "docs/title" $page) | jsonify }},
'section': {{ (partial "docs/title" $page.Parent) | jsonify }},
2019-10-27 10:58:58 +00:00
'content': {{ $page.Plain | jsonify }}
});
{{- end -}}
{{- end -}}
2019-07-16 12:34:02 +00:00
})();