This is an automated email from the ASF dual-hosted git repository.

zregvart pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-website.git

commit 73bcb8b50ab8120b50faeb43af0c73b1d487f9be
Author: Zoran Regvart <[email protected]>
AuthorDate: Wed Feb 23 22:49:14 2022 +0100

    refactor(search): align with new index
    
    The Algolia Crawler configuration is now under our direct control, so
    we can extract attributes that we could not extract with the DocSearch
    crawler. We can now set the `version` attribute, and read it from there
    rather than from `lvl6`. There is also `categories` attribute, which
    currently we do not display in the search results.
    Some refinement and simplifications are also included.
---
 .../src/js/vendor/algoliasearch.bundle.js          | 41 +++++++++-------------
 1 file changed, 16 insertions(+), 25 deletions(-)

diff --git a/antora-ui-camel/src/js/vendor/algoliasearch.bundle.js 
b/antora-ui-camel/src/js/vendor/algoliasearch.bundle.js
index 9aeab31..a1d4920 100644
--- a/antora-ui-camel/src/js/vendor/algoliasearch.bundle.js
+++ b/antora-ui-camel/src/js/vendor/algoliasearch.bundle.js
@@ -51,23 +51,19 @@
           .then((results) => {
             const hits = results.hits
             const data = hits.reduce((data, hit) => {
-              const d = {}
-              d.url = hit.url
-              var section = hit.hierarchy.lvl0
-              if (hit.hierarchy.lvl6 !== null) section = section + '/' + 
hit.hierarchy.lvl6
-              var breadcrumbs = Object.values(hit.hierarchy)
-                .slice(1)
-                .filter((lvl) => lvl !== null)
-                .join(' / ')
+              const section = hit.hierarchy.lvl0
+              const sectionKey = `${section}-${hit.version || ''}`
 
-              d.breadcrumbs = ((breadcrumbs !== '') ? breadcrumbs : section)
-              d.snippet = hit._snippetResult.content.value
-              if (d.snippet !== undefined || d.snippet !== null) {
-                d.snippet = d.snippet.split('&quot;').join('') + '...'
-              }
-
-              data[section] = data[section] || []
-              data[section].push(d)
+              data[sectionKey] = data[sectionKey] || []
+              data[sectionKey].name = section
+              data[sectionKey].version = hit.version
+              data[sectionKey].push({
+                url: hit.url,
+                section,
+                categories: hit.categories,
+                breadcrumbs: 
Object.values(hit.hierarchy).slice(1).filter((lvl) => lvl !== null).join(' / '),
+                snippet: hit._highlightResult.content.value,
+              })
 
               return data
             }, {})
@@ -88,13 +84,13 @@
               <dl>
                 ${Object.keys(data)
     .map(
-      (section) => `
+      (sectionKey) => `
                   <div class="result">
                     <div class="heading">
-                      <dt>${section.split('/')[0]}</dt>
-                      <dt class="version">${section.split('/')[1]}</dt>
+                      <dt>${data[sectionKey].name}</dt>
+                      ${(data[sectionKey].version && `<dt 
class="version">${data[sectionKey].version}</dt>`) || ''}
                     </div>
-                    ${data[section]
+                    ${data[sectionKey]
     .map(
       (hit) => `
                     <a href="${hit.url}">
@@ -119,11 +115,6 @@
           })
           .then((markup) => {
             results.innerHTML = markup
-            Array.from(results.querySelectorAll('.version')).forEach((version) 
=> {
-              if (version.innerHTML === 'undefined') {
-                version.style.display = 'none'
-              }
-            })
             container.className = 'navbar-search'
           })
       }, 150)

Reply via email to