summaryrefslogtreecommitdiff
path: root/assets
diff options
context:
space:
mode:
authoruvok cheetah2020-05-23 16:01:46 +0200
committeruvok cheetah2020-05-23 16:01:46 +0200
commitb73cf12240749595ee1232462f965d15e5538555 (patch)
tree0abe4bea6abea559ce5ca04003923c7a46da9417 /assets
parent1046c86029abc29c02b679473679731752e8bc5e (diff)
Put search and index in different file
Diffstat (limited to 'assets')
-rw-r--r--assets/js/search.js30
1 files changed, 30 insertions, 0 deletions
diff --git a/assets/js/search.js b/assets/js/search.js
new file mode 100644
index 0000000..8784541
--- /dev/null
+++ b/assets/js/search.js
@@ -0,0 +1,30 @@
+---
+---
+
+// 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);
+});
+
+
+function do_search(queryterm) {
+ return idx.search(queryterm);
+}