From b73cf12240749595ee1232462f965d15e5538555 Mon Sep 17 00:00:00 2001
From: uvok cheetah
Date: Sat, 23 May 2020 16:01:46 +0200
Subject: Put search and index in different file

---
 assets/js/search.js | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
 create mode 100644 assets/js/search.js

(limited to 'assets')

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);
+}
-- 
cgit v1.2.3