diff options
-rw-r--r-- | assets/js/search.js | 30 | ||||
-rw-r--r-- | search.html | 27 |
2 files changed, 32 insertions, 25 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); +} diff --git a/search.html b/search.html index 84d89a6..b4794e2 100644 --- a/search.html +++ b/search.html @@ -2,30 +2,7 @@ layout: page --- <script src="/assets/js/lunr.min.js"></script> -<script> - // 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); - }); -</script> +<script src="/assets/js/search.js"></script> <p> <input id="input_qterm"></input> @@ -40,7 +17,7 @@ layout: page <script> // search function query(queryterm) { - var result = idx.search(queryterm); + var result = do_search(queryterm); const rbase = document.getElementById("results") rbase.textContent = ""; if (result.length) { |