fix search issues
parent
e1c3c1a51e
commit
b90fbbedd2
|
@ -1,6 +1,3 @@
|
||||||
- ENHANCEMENT
|
- BUGFIX
|
||||||
- Rework search as a dropdown list #38 (@LukasHirt)
|
- fix empty search list after pae refresh
|
||||||
- Use option `geekdocSearchShowParent` to group search results by parent #38 (@LukasHirt).
|
- fix search issue if `geekdocSearchShowParent` is disabled
|
||||||
This is changing the current behavior of prefixing search results with the parent by
|
|
||||||
grouped nested lists.
|
|
||||||
- Add `ok` color option for `hint` shortcode
|
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
const results = document.querySelector('#gdoc-search-results');
|
const results = document.querySelector('#gdoc-search-results');
|
||||||
let showParent = false
|
let showParent = false
|
||||||
|
|
||||||
{{ if .Site.Params.GeekdocSearchShowParent }}
|
{{ if .Site.Params.GeekdocSearchShowParent }}
|
||||||
showParent = true
|
showParent = true
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
|
@ -19,12 +19,12 @@
|
||||||
input.removeEventListener('focus', init); // init once
|
input.removeEventListener('focus', init); // init once
|
||||||
input.required = true;
|
input.required = true;
|
||||||
|
|
||||||
|
loadScript('{{ index .Site.Data.assets "js/groupBy.min.js" | relURL }}');
|
||||||
loadScript('{{ index .Site.Data.assets "js/flexsearch.min.js" | relURL }}');
|
loadScript('{{ index .Site.Data.assets "js/flexsearch.min.js" | relURL }}');
|
||||||
loadScript('{{ $searchData.RelPermalink }}', function() {
|
loadScript('{{ $searchData.RelPermalink }}', function() {
|
||||||
input.required = false;
|
input.required = false;
|
||||||
search();
|
search();
|
||||||
});
|
});
|
||||||
loadScript('{{ index .Site.Data.assets "js/groupBy.min.js" | relURL }}');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function search() {
|
function search() {
|
||||||
|
@ -33,14 +33,10 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!input.value) {
|
if (!input.value) {
|
||||||
console.log("empty")
|
return results.classList.remove("has-hits");
|
||||||
results.classList.remove("has-hits");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let searchHits = window.geekdocSearchIndex.search(input.value, 10);
|
let searchHits = window.geekdocSearchIndex.search(input.value, 10);
|
||||||
|
|
||||||
console.log(searchHits.length);
|
|
||||||
if (searchHits.length < 1) {
|
if (searchHits.length < 1) {
|
||||||
return results.classList.remove("has-hits");
|
return results.classList.remove("has-hits");
|
||||||
}
|
}
|
||||||
|
@ -53,16 +49,24 @@
|
||||||
|
|
||||||
const items = [];
|
const items = [];
|
||||||
|
|
||||||
for (const section in searchHits) {
|
if (showParent) {
|
||||||
const item = document.createElement('li');
|
for (const section in searchHits) {
|
||||||
|
const item = document.createElement('li'),
|
||||||
|
title = item.appendChild(document.createElement('span')),
|
||||||
|
subList = item.appendChild(document.createElement('ul'));
|
||||||
|
|
||||||
if (showParent) {
|
|
||||||
const title = item.appendChild(document.createElement('span'));
|
|
||||||
title.textContent = section;
|
title.textContent = section;
|
||||||
}
|
createLinks(searchHits[section], subList);
|
||||||
|
|
||||||
const subList = item.appendChild(document.createElement('ul'));
|
items.push(item);
|
||||||
createLinks(searchHits[section], subList);
|
}
|
||||||
|
} else {
|
||||||
|
const item = document.createElement('li'),
|
||||||
|
title = item.appendChild(document.createElement('span')),
|
||||||
|
subList = item.appendChild(document.createElement('ul'));
|
||||||
|
|
||||||
|
title.textContent = "Results";
|
||||||
|
createLinks(searchHits, subList);
|
||||||
|
|
||||||
items.push(item);
|
items.push(item);
|
||||||
}
|
}
|
||||||
|
@ -104,12 +108,12 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadScript(src, callback) {
|
function loadScript(src, callback) {
|
||||||
const script = document.createElement('script');
|
let script = document.createElement('script');
|
||||||
script.defer = true;
|
script.defer = true;
|
||||||
script.async = false;
|
script.async = true;
|
||||||
script.src = src;
|
script.src = src;
|
||||||
script.onload = callback;
|
script.onload = callback;
|
||||||
|
|
||||||
document.head.appendChild(script);
|
document.body.appendChild(script);
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -463,7 +463,7 @@ img {
|
||||||
|
|
||||||
> li > span {
|
> li > span {
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
color: $gray-600;
|
color: $gray-700;
|
||||||
}
|
}
|
||||||
|
|
||||||
> li + li {
|
> li + li {
|
||||||
|
|
Loading…
Reference in New Issue