fix search issues

uci-hugo-doc
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
- Rework search as a dropdown list #38 (@LukasHirt)
- Use option `geekdocSearchShowParent` to group search results by parent #38 (@LukasHirt).
This is changing the current behavior of prefixing search results with the parent by
grouped nested lists.
- Add `ok` color option for `hint` shortcode
- BUGFIX
- fix empty search list after pae refresh
- fix search issue if `geekdocSearchShowParent` is disabled

View File

@ -8,7 +8,7 @@
const results = document.querySelector('#gdoc-search-results');
let showParent = false
{{ if .Site.Params.GeekdocSearchShowParent }}
{{ if .Site.Params.GeekdocSearchShowParent }}
showParent = true
{{ end }}
@ -19,12 +19,12 @@
input.removeEventListener('focus', init); // init once
input.required = true;
loadScript('{{ index .Site.Data.assets "js/groupBy.min.js" | relURL }}');
loadScript('{{ index .Site.Data.assets "js/flexsearch.min.js" | relURL }}');
loadScript('{{ $searchData.RelPermalink }}', function() {
input.required = false;
search();
});
loadScript('{{ index .Site.Data.assets "js/groupBy.min.js" | relURL }}');
}
function search() {
@ -33,14 +33,10 @@
}
if (!input.value) {
console.log("empty")
results.classList.remove("has-hits");
return;
return results.classList.remove("has-hits");
}
let searchHits = window.geekdocSearchIndex.search(input.value, 10);
console.log(searchHits.length);
if (searchHits.length < 1) {
return results.classList.remove("has-hits");
}
@ -53,16 +49,24 @@
const items = [];
for (const section in searchHits) {
const item = document.createElement('li');
if (showParent) {
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;
}
createLinks(searchHits[section], subList);
const subList = item.appendChild(document.createElement('ul'));
createLinks(searchHits[section], subList);
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);
}
@ -104,12 +108,12 @@
}
function loadScript(src, callback) {
const script = document.createElement('script');
let script = document.createElement('script');
script.defer = true;
script.async = false;
script.async = true;
script.src = src;
script.onload = callback;
document.head.appendChild(script);
document.body.appendChild(script);
}
})();

View File

@ -463,7 +463,7 @@ img {
> li > span {
font-weight: bold;
color: $gray-600;
color: $gray-700;
}
> li + li {