diff options
author | Alex Shpak <alex-shpak@users.noreply.github.com> | 2019-07-15 18:25:21 +0200 |
---|---|---|
committer | Alex Shpak <alex-shpak@users.noreply.github.com> | 2019-08-06 11:33:42 +0200 |
commit | dda0a0eab19457598b71f2b2b2f978b09d3f95c7 (patch) | |
tree | 035ca254fe7a8c7c7df316bce0b777f9a9dd06fe /exampleSite/resources/_gen/assets/js/search.js_db9e329433ffca0798ed12c88043b3b3.content | |
parent | b199d72e5fd7ec76b3c17fc9a6368868978d6328 (diff) |
Start work on search feature with lunr
Diffstat (limited to 'exampleSite/resources/_gen/assets/js/search.js_db9e329433ffca0798ed12c88043b3b3.content')
-rw-r--r-- | exampleSite/resources/_gen/assets/js/search.js_db9e329433ffca0798ed12c88043b3b3.content | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/exampleSite/resources/_gen/assets/js/search.js_db9e329433ffca0798ed12c88043b3b3.content b/exampleSite/resources/_gen/assets/js/search.js_db9e329433ffca0798ed12c88043b3b3.content new file mode 100644 index 0000000..9c34794 --- /dev/null +++ b/exampleSite/resources/_gen/assets/js/search.js_db9e329433ffca0798ed12c88043b3b3.content @@ -0,0 +1,6 @@ +addEventListener("load",function(){let input=document.querySelector("#book-search");let results=document.querySelector("#book-search-results");Promise.all([loadScript("/example/lunr.min.js"),loadScript("/example/index.json")]).then(enableLunr);function enableLunr(){results.idx=lunr(function(){this.ref('href') +this.field('title') +this.field('content') +window.lunrData.forEach(function(page){this.add(page)},this)});input.addEventListener("keyup",search);} +function search(){if(input.value){var hits=results.idx.search(`${input.value}*`);results.innerHTML=JSON.stringify(hits);}else{results.innerHTML='';}} +function loadScript(src){return new Promise(function(resolve,reject){let script=document.createElement('script');script.src=src;script.onload=()=>resolve(script);document.head.append(script);});}});
\ No newline at end of file |