mirror of
https://github.com/alex-shpak/hugo-book.git
synced 2024-11-22 03:19:25 +00:00
Jsonify title in search as well
This commit is contained in:
parent
b95fbf9750
commit
df8d186d38
@ -1,11 +1,11 @@
|
||||
(function() {
|
||||
const pages = [
|
||||
{{ range $index, $page := .Site.Pages }}
|
||||
{{- if and $index (gt $index 0) -}},{{- end }}
|
||||
{{- if $index -}},{{- end }}
|
||||
{
|
||||
"idx": {{ $index }},
|
||||
"href": "{{ $page.RelPermalink }}",
|
||||
"title": "{{ partial "docs/title" $page }}",
|
||||
"title": {{ (partial "docs/title" $page) | jsonify}},
|
||||
"content": {{ $page.Plain | jsonify }}
|
||||
}
|
||||
{{- end -}}
|
||||
@ -15,7 +15,7 @@
|
||||
pages: pages,
|
||||
idx: lunr(function() {
|
||||
this.ref("idx");
|
||||
this.field("title", { boost: 10000 });
|
||||
this.field("title");
|
||||
this.field("content");
|
||||
|
||||
pages.forEach(this.add, this);
|
||||
|
File diff suppressed because one or more lines are too long
@ -1 +1 @@
|
||||
{"Target":"search-data.min.34183091f91a205581bbdcc247f638b72d22f51e34ab573b24519f95c4a92895.js","MediaType":"application/javascript","Data":{"Integrity":"sha256-NBgwkfkaIFWBu9zCR/Y4ty0i9R40q1c7JFGflcSpKJU="}}
|
||||
{"Target":"search-data.min.c533c453016d71fbd7fb228486a062cd64dfc3987b3d5c118b93c450abba2bc7.js","MediaType":"application/javascript","Data":{"Integrity":"sha256-xTPEUwFtcfvX+yKEhqBizWTfw5h7PVwRi5PEUKu6K8c="}}
|
@ -1,4 +1,4 @@
|
||||
(function(){const input=document.querySelector("#book-search-input");const results=document.querySelector("#book-search-results");input.addEventListener("focus",init);input.addEventListener("keyup",search);function init(){input.removeEventListener("focus",init);input.required=true;loadScript("/example/lunr.min.js");loadScript("/example/search-data.min.34183091f91a205581bbdcc247f638b72d22f51e34ab573b24519f95c4a92895.js",function(){input.readOnly=false;input.required=false;search();});}
|
||||
(function(){const input=document.querySelector("#book-search-input");const results=document.querySelector("#book-search-results");input.addEventListener("focus",init);input.addEventListener("keyup",search);function init(){input.removeEventListener("focus",init);input.required=true;loadScript("/example/lunr.min.js");loadScript("/example/search-data.min.c533c453016d71fbd7fb228486a062cd64dfc3987b3d5c118b93c450abba2bc7.js",function(){input.readOnly=false;input.required=false;search();});}
|
||||
function search(){while(results.firstChild){results.removeChild(results.firstChild);}
|
||||
if(!input.value){return;}
|
||||
const terms=lunr.tokenizer(input.value);const searchHits=window.bookSearch.idx.query(function(query){query.term(terms,{boost:100});query.term(terms,{boost:10,wildcard:lunr.Query.wildcard.LEADING|lunr.Query.wildcard.TRAILING});query.term(terms,{editDistance:2});});searchHits.slice(0,10).forEach(function(hit){const page=window.bookSearch.pages[hit.ref];const li=document.createElement("li"),a=li.appendChild(document.createElement("a"));a.href=page.href;a.textContent=page.title;results.appendChild(li);});}
|
||||
|
@ -1 +1 @@
|
||||
{"Target":"search.min.ea6096df2339354acbfe0aec0b99caded625821549e54c3b140a20f57db99984.js","MediaType":"application/javascript","Data":{"Integrity":"sha256-6mCW3yM5NUrL/grsC5nK3tYlghVJ5Uw7FAog9X25mYQ="}}
|
||||
{"Target":"search.min.edaedcc6b2019bf664c7f86c5194c481866cf4d4be6e95edab005a627efefda1.js","MediaType":"application/javascript","Data":{"Integrity":"sha256-7a7cxrIBm/Zkx/hsUZTEgYZs9NS+bpXtqwBaYn7+/aE="}}
|
Loading…
Reference in New Issue
Block a user