#80, Migrate to flexsearch
This commit is contained in:
+17
-11
@@ -3,22 +3,28 @@
|
||||
{{ range $index, $page := .Site.Pages }}
|
||||
{{- if $index -}},{{- end }}
|
||||
{
|
||||
"idx": {{ $index }},
|
||||
"href": "{{ $page.RelPermalink }}",
|
||||
"title": {{ (partial "docs/title" $page) | jsonify }},
|
||||
"content": {{ $page.Plain | jsonify }}
|
||||
'idx': {{ $index }},
|
||||
'href': '{{ $page.RelPermalink }}',
|
||||
'title': {{ (partial "docs/title" $page) | jsonify }},
|
||||
'content': {{ $page.Plain | jsonify }}
|
||||
}
|
||||
{{- end -}}
|
||||
];
|
||||
|
||||
var index = new FlexSearch({
|
||||
cache: true,
|
||||
encode: 'balance',
|
||||
/* tokenize: function(str) {
|
||||
return str.replace(/[\x00-\x7F]/g, ' ').split('');
|
||||
} */
|
||||
});
|
||||
|
||||
pages.forEach(function(page, x) {
|
||||
index.add(x, pages[x].content);
|
||||
})
|
||||
|
||||
window.bookSearch = {
|
||||
pages: pages,
|
||||
idx: lunr(function() {
|
||||
this.ref("idx");
|
||||
this.field("title");
|
||||
this.field("content");
|
||||
|
||||
pages.forEach(this.add, this);
|
||||
}),
|
||||
index: index,
|
||||
}
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user