2019-10-27 10:58:58 +00:00
|
|
|
'use strict';
|
|
|
|
|
2019-07-16 12:34:02 +00:00
|
|
|
(function() {
|
2019-11-13 23:23:01 +00:00
|
|
|
const indexCfg = {{ with .Scratch.Get "bookSearchConfig" }}
|
2019-11-10 13:35:07 +00:00
|
|
|
{{ . }};
|
|
|
|
{{ 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'],
|
|
|
|
};
|
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
|
|
|
|
2019-10-27 10:58:58 +00:00
|
|
|
{{ range $index, $page := .Site.Pages }}
|
|
|
|
index.add({
|
|
|
|
'id': {{ $index }},
|
|
|
|
'href': '{{ $page.RelPermalink }}',
|
|
|
|
'title': {{ (partial "docs/title" $page) | jsonify }},
|
|
|
|
'content': {{ $page.Plain | jsonify }}
|
|
|
|
});
|
|
|
|
{{- end -}}
|
2019-07-16 12:34:02 +00:00
|
|
|
})();
|