fix search issues

master
Robert Kaussow 2020-12-23 16:43:41 +01:00
parent e1c3c1a51e
commit b90fbbedd2
No known key found for this signature in database
GPG Key ID: 65362AE74AF98B61
3 changed files with 25 additions and 24 deletions

View File

@ -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

View File

@ -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,19 +49,27 @@
const items = []; const items = [];
for (const section in searchHits) {
const item = document.createElement('li');
if (showParent) { if (showParent) {
const title = item.appendChild(document.createElement('span')); for (const section in searchHits) {
title.textContent = section; const item = document.createElement('li'),
} title = item.appendChild(document.createElement('span')),
subList = item.appendChild(document.createElement('ul'));
const subList = item.appendChild(document.createElement('ul')); title.textContent = section;
createLinks(searchHits[section], subList); createLinks(searchHits[section], subList);
items.push(item); items.push(item);
} }
} 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.forEach(item => { items.forEach(item => {
results.appendChild(item); results.appendChild(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);
} }
})(); })();

View File

@ -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 {