Skip to content

Commit

Permalink
docs: improve search result UI (#16187)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenxsan committed Aug 10, 2022
1 parent d0f4cb4 commit 784096d
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion docs/src/assets/js/search.js
Expand Up @@ -70,9 +70,10 @@ function displaySearchResults(results) {
for (const result of results) {
const listItem = document.createElement('li');
listItem.classList.add('search-results__item');
const maxLvl = Math.max(...Object.keys(result._highlightResult.hierarchy).map(k => Number(k.substring(3))));
listItem.innerHTML = `
<h2 class="search-results__item__title"><a href="${result.url}">${result.hierarchy.lvl0}</a></h2>
<p class="search-results__item__context">${result._highlightResult.hierarchy.lvl0.value}</p>
<p class="search-results__item__context">${typeof result._highlightResult.content !== 'undefined' ? result._highlightResult.content.value : result._highlightResult.hierarchy[`lvl${maxLvl}`].value}</p>
`.trim();
list.append(listItem);
}
Expand Down

0 comments on commit 784096d

Please sign in to comment.