aboutsummaryrefslogtreecommitdiff
path: root/assets/search-data.js
diff options
context:
space:
mode:
Diffstat (limited to 'assets/search-data.js')
-rw-r--r--assets/search-data.js45
1 files changed, 20 insertions, 25 deletions
diff --git a/assets/search-data.js b/assets/search-data.js
index 6848438..a3fd51b 100644
--- a/assets/search-data.js
+++ b/assets/search-data.js
@@ -1,30 +1,25 @@
+'use strict';
+
(function() {
- const pages = [
- {{ range $index, $page := .Site.Pages }}
- {{- if $index -}},{{- end }}
- {
- 'idx': {{ $index }},
- 'href': '{{ $page.RelPermalink }}',
- 'title': {{ (partial "docs/title" $page) | jsonify }},
- 'content': {{ $page.Plain | jsonify }}
- }
- {{- end -}}
- ];
+ const indexCfg = {{ with .Site.Params.BookSearchConfig }}
+ {{ . }}
+ {{ end }};
- var index = new FlexSearch({
- cache: true,
- encode: 'balance',
- /* tokenize: function(str) {
- return str.replace(/[\x00-\x7F]/g, ' ').split('');
- } */
- });
+ indexCfg.doc = {
+ id: 'id',
+ field: ['title', 'content'],
+ store: ['title', 'href'],
+ };
- pages.forEach(function(page, x) {
- index.add(x, pages[x].content);
- })
+ const index = FlexSearch.create('balance', indexCfg);
+ window.bookSearchIndex = index;
- window.bookSearch = {
- pages: pages,
- index: index,
- }
+ {{ range $index, $page := .Site.Pages }}
+ index.add({
+ 'id': {{ $index }},
+ 'href': '{{ $page.RelPermalink }}',
+ 'title': {{ (partial "docs/title" $page) | jsonify }},
+ 'content': {{ $page.Plain | jsonify }}
+ });
+ {{- end -}}
})();