summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoruvok cheetah2020-05-24 19:18:15 +0200
committeruvok cheetah2020-05-24 19:18:15 +0200
commit04b7f70a788a078763b5559bba8a8fdebe6630a2 (patch)
treee3f565b8f9f069fdb248d401b935c8e6c922b27e
parent5231bb9a84d177948a5fde46a0d8e2cb7adcb7ea (diff)
Wrap pages/idx in function, only make search visible
-rw-r--r--assets/js/search.js53
1 files changed, 28 insertions, 25 deletions
diff --git a/assets/js/search.js b/assets/js/search.js
index 8584810..68f56ff 100644
--- a/assets/js/search.js
+++ b/assets/js/search.js
@@ -1,31 +1,34 @@
---
---
-// 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 %}
-];
+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 %}
+ ];
-// index
-var idx = lunr(function () {
- this.ref('url');
- this.field('title');
- this.field('content');
- pages.forEach(function (doc) {
- this.add(doc);
- }, this);
-});
+ // index
+ const idx = lunr(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));
+ }
-function do_search(queryterm) {
- const result = idx.search(queryterm);
- return result.map(r => pages.find((p) => p.id === r.ref));
-}
+ return do_search;
+}();