Skip to content

Commit

Permalink
feat: optimize search result
Browse files Browse the repository at this point in the history
  • Loading branch information
chenxsan committed Aug 10, 2022
1 parent cf15789 commit e6b754e
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions 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.lvl1}</a></h2>
<p class="search-results__item__context">${result._highlightResult.hierarchy.lvl1.value}</p>
<h2 class="search-results__item__title"><a href="${result.url}">${result.hierarchy.lvl0}</a></h2>
<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 e6b754e

Please sign in to comment.