Start work on search feature with lunr

This commit is contained in:
Alex Shpak
2019-07-15 18:25:21 +02:00
parent b199d72e5f
commit dda0a0eab1
26 changed files with 148 additions and 75 deletions
+7 -5
View File
@@ -14,6 +14,9 @@ enableGitInfo = true
# pygmentsStyle = 'monokailight'
pygmentsCodeFences = true
[outputs]
home = ["HTML", "JSON"]
[params]
# (Optional, default 6) Set how many table of contents levels to be showed on page.
# Use false to hide ToC, note that 0 will default to 6 (https://gohugo.io/functions/default/)
@@ -28,13 +31,9 @@ pygmentsCodeFences = true
# You can also set value to '*' to render all sections to menu
BookSection = 'docs'
# This value is duplicate of $link-color for making active link highlight in menu bundle mode
# (Optional) This value is duplicate of $link-color for making active link highlight in menu bundle mode
# BookMenuBundleActiveLinkColor = '\#004ed0'
# Include JS scripts in pages. Disabled by default.
# - Keep side menu on same scroll position during navigation
BookEnableJS = true
# Set source repository location.
# Used for 'Last Modified' and 'Edit this page' links.
BookRepo = 'https://github.com/alex-shpak/hugo-book'
@@ -48,3 +47,6 @@ pygmentsCodeFences = true
# - In git information
# - In blog posts
BookDateFormat = 'Jan 2, 2006'
# (Optional, default true) Enables or disables search function with lunr.js
BookSearch = true
+2 -6
View File
@@ -28,12 +28,8 @@ params:
# You can also set value to '*' to render all sections to menu
BookSection: docs
# This value is duplicate of $link-color for making active link highlight in menu bundle mode
# BookMenuBundleActiveLinkColor: \#004ed0
# Include JS scripts in pages. Disabled by default.
# - Keep side menu on same scroll position during navigation
BookEnableJS: true
# (Optional) This value is duplicate of $link-color for making active link highlight in menu bundle mode
# BookMenuBundleActiveLinkColor: "\#004ed0"
# Set source repository location.
# Used for 'Last Modified' and 'Edit this page' links.
@@ -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);});}});
@@ -0,0 +1 @@
{"Target":"search.min.f37565c4baa28364f7b8e1e53c35bdb0ab92f2215165bd3f083f3f4f1ae78c71.js","MediaType":"application/javascript","Data":{"Integrity":"sha256-83VlxLqig2T3uOHlPDW9sKuS8iFRZb0/CD8/TxrnjHE="}}
File diff suppressed because one or more lines are too long
@@ -1 +1 @@
{"Target":"book.min.f4161f5e2de53a2e927f51df1611323a2a12cccb2681f23cb6fc3517852e8643.css","MediaType":"text/css","Data":{"Integrity":"sha256-9BYfXi3lOi6Sf1HfFhEyOioSzMsmgfI8tvw1F4UuhkM="}}
{"Target":"book.min.60422b170f7beee5a981f3288523ee2bf275a0b48eba3a8983a3736189b9027f.css","MediaType":"text/css","Data":{"Integrity":"sha256-YEIrFw977uWpgfMohSPuK/J1oLSOujqJg6NzYYm5An8="}}