diff options
author | David O'Regan <doregan@gitlab.com> | 2021-07-09 01:00:22 +0300 |
---|---|---|
committer | Evan Read <eread@gitlab.com> | 2021-07-09 01:00:22 +0300 |
commit | be4ba4a26bd315e172eedd28672e0554ddcc87a9 (patch) | |
tree | 73e1f0cf1e6ef846f71f9dad0bfbc7a1e79b9bb7 | |
parent | 93fa4d11d44a19974a103d37efe39b3dec96cbb6 (diff) |
Refine search results formatting
-rw-r--r-- | content/frontend/search/index.js | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/content/frontend/search/index.js b/content/frontend/search/index.js index a021643e..f63f6e96 100644 --- a/content/frontend/search/index.js +++ b/content/frontend/search/index.js @@ -1,3 +1,4 @@ +/* eslint-disable no-underscore-dangle */ import instantsearch from '@tnir/instantsearch.js'; import { singleIndexQ } from '@tnir/instantsearch.js/es/lib/stateMappings'; import { @@ -53,7 +54,20 @@ document.addEventListener('DOMContentLoaded', () => { infiniteHits({ container: '#hits', templates: { - item: document.getElementById('hit-template').innerHTML, + item(hit) { + const content = hit._highlightResult.content.value.replaceAll('&quot;', '"'); + return ` + <a href="${hit.url}" class="hit"> + <div class="hit-content"> + <h3 class="hit-name lvl0">${hit._highlightResult.hierarchy.lvl0.value}</h3> + <h4 class="hit-description lvl1">${hit._highlightResult.hierarchy.lvl1.value}</h4> + <h5 class="hit-description lvl2">${hit._highlightResult.hierarchy.lvl2.value}</h5> + <div class="hit-text">${content}</div> + <div class="hit-tag">${hit.tags}</div> + </div> + </a> + `; + }, empty: 'We didn\'t find any results for the search <em>"{{query}}"</em>', }, escapeHits: true, |