blob: 1ddb26469a91470b0e09a4d9ac6f94c8a4238598 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
---
---
const do_search = function() {
// data
var pages = [
{% for post in site.posts %}
{
"id": "{{ post.url | slufigy }}",
"title": {{ post.title | jsonify }},
"content": {{ post.content | strip_html | jsonify }},
"url": "{{ post.url | xml_escape }}"
}
{% unless forloop.last %},{% endunless %}
{% endfor %}
];
var mylunr = function (config) {
var builder = new lunr.Builder
// no pipeline
config.call(builder, builder)
return builder.build()
}
// index
const idx = mylunr(function () {
this.ref('url');
this.field('title');
this.field('content');
pages.forEach(function (doc) {
this.add(doc);
}, this);
});
function do_search(queryterm) {
const result = idx.search(queryterm);
return result.map(r => pages.find((p) => p.id === r.ref));
}
return do_search;
}();
|