forked from alex-shpak/hugo-book
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start work on search feature with lunr
- Loading branch information
1 parent
b199d72
commit dda0a0e
Showing
26 changed files
with
148 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
addEventListener("load", function() { | ||
let input = document.querySelector("#book-search"); | ||
let results = document.querySelector("#book-search-results"); | ||
|
||
Promise.all([ | ||
loadScript("{{ "lunr.min.js" | relURL }}"), | ||
loadScript("{{ "index.json" | relURL }}") | ||
]).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); | ||
}); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
exampleSite/resources/_gen/assets/js/search.js_db9e329433ffca0798ed12c88043b3b3.content
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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);});}}); |
1 change: 1 addition & 0 deletions
1
exampleSite/resources/_gen/assets/js/search.js_db9e329433ffca0798ed12c88043b3b3.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"Target":"search.min.f37565c4baa28364f7b8e1e53c35bdb0ab92f2215165bd3f083f3f4f1ae78c71.js","MediaType":"application/javascript","Data":{"Integrity":"sha256-83VlxLqig2T3uOHlPDW9sKuS8iFRZb0/CD8/TxrnjHE="}} |
2 changes: 1 addition & 1 deletion
2
exampleSite/resources/_gen/assets/scss/book.scss_48b060fe05b0a273d182ef83c0605941.content
Large diffs are not rendered by default.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
exampleSite/resources/_gen/assets/scss/book.scss_48b060fe05b0a273d182ef83c0605941.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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="}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
<!DOCTYPE html> | ||
{{- partial "docs/shared" -}} | ||
<html lang="{{ .Site.Language.Lang }}"> | ||
|
||
<head> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
<!DOCTYPE html> | ||
{{- partial "docs/shared" -}} | ||
<html lang="{{ .Site.Language.Lang }}"> | ||
|
||
<head> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
<!DOCTYPE html> | ||
{{- partial "docs/shared" -}} | ||
<html lang="{{ .Site.Language.Lang }}"> | ||
|
||
<head> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
window.lunrData = [ | ||
{{ range $index, $page := .Site.Pages }} | ||
{{- if and $index (gt $index 0) -}},{{- end }} | ||
{ | ||
"href": "{{ $page.RelPermalink }}", | ||
"title": "{{ htmlEscape $page.Title }}", | ||
"content": {{ $page.Plain | jsonify }} | ||
} | ||
{{- end -}} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<h2 class="book-brand"> | ||
<a href="{{ .Site.BaseURL }}">{{ .Site.Title }}</a> | ||
</h2> | ||
</h2> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<header class="align-center justify-between book-header"> | ||
<header class="flex align-center justify-between book-header"> | ||
<label for="menu-control"> | ||
<img src="{{ "svg/menu.svg" | relURL }}" alt="Menu" /> | ||
</label> | ||
<strong>{{- template "title" . }}</strong> | ||
<strong>{{ partial "docs/title" . }}</strong> | ||
</header> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<input type="text" placeholder="Search" class="book-search" id="book-search" /> | ||
<ul id="book-search-results"></ul> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{{ $title := .Title }} | ||
{{ if and .IsSection .File }} | ||
{{ $sections := split (trim .File.Dir "/") "/" }} | ||
{{ $title = index ($sections | last 1) 0 | humanize | title }} | ||
{{ else if and .IsPage .File }} | ||
{{ $title = .File.BaseFileName | humanize | title }} | ||
{{ end }} | ||
|
||
{{ return $title }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
<!DOCTYPE html> | ||
{{- partial "docs/shared" -}} | ||
<html lang="{{ .Site.Language.Lang }}"> | ||
|
||
<head> | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters