-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,3 +17,108 @@ | |
|
||
<!-- Syntax Highlighting CSS --> | ||
<link rel="preload" href="https://cdn.jsdelivr.net/npm/[email protected]/themes/prism-tomorrow.min.css" as="style" onload="this.onload=null;this.rel='stylesheet'" crossorigin="anonymous" referrerpolicy="no-referrer"/> | ||
|
||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/themes/reset-min.css" integrity="sha256-KvFgFCzgqSErAPu6y9gz/AhZAvzK48VJASu3DpNLCEQ=" crossorigin="anonymous"> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@algolia/[email protected]"/> | ||
|
||
<script type="text/javascript"> | ||
const searchScope = document.head.querySelector('[property="article:section"][content]')?.content ?? ''; | ||
function initSearchBar() { | ||
const {autocomplete, getAlgoliaResults} = window['@algolia/autocomplete-js']; | ||
const searchClient = algoliasearch('KWE0727TZS', '595ee07f069991380e9c3036cfad8e5e'); | ||
const scopeTitles = { | ||
'ama': 'Ask Me Anything', | ||
'blog': 'Blog', | ||
'changelog': 'Changelog', | ||
'customer-stories': 'Customer Stories', | ||
'docs': 'Docs', | ||
'ebooks': 'E-Books', | ||
'handbook': 'Handbook', | ||
'node-red': 'Node-RED', | ||
'webinars': 'Webinars', | ||
} | ||
const placeholder = Object.prototype.hasOwnProperty.call(scopeTitles, searchScope) ? `Search in ${scopeTitles[searchScope]}...` : 'Search...' | ||
const searchQuery = (searchClient, query, scope) => { | ||
return { | ||
sourceId : scope, | ||
getItems : () => getAlgoliaResults({ | ||
searchClient, | ||
queries: [ | ||
{ | ||
indexName : 'netlify_00f8cf60-997f-4c4d-9427-a97924358648_live_all', | ||
params : { | ||
query, | ||
hitsPerPage: 5, | ||
}, | ||
attributesToHighlight: '*', | ||
filters: scope.length === 0 ? undefined : `category:${scope}` | ||
}, | ||
], | ||
}), | ||
templates: { | ||
header({html}) { | ||
if (!Object.prototype.hasOwnProperty.call(scopeTitles, scope)) { | ||
return null; | ||
} | ||
return html` | ||
<span class="aa-SourceHeaderTitle">In ${scopeTitles[scope]}</span> | ||
<div class="aa-SourceHeaderLine"/> | ||
`; | ||
}, | ||
item({item, components, html}) { | ||
return html` | ||
<a href="${item.url}" class="aa-ItemWrapper"> | ||
<div class="aa-ItemContent"> | ||
<div class="aa-ItemIcon aa-ItemIcon--alignTop"> | ||
<img | ||
src="${item.image}" | ||
alt="${item.name}" | ||
width="40" | ||
height="40" | ||
/> | ||
</div> | ||
<div class="aa-ItemContentBody"> | ||
<div class="aa-ItemContentTitle"> | ||
${components.Highlight({ | ||
hit : item, | ||
attribute: ['hierarchy', 'lvl0'], | ||
})} | ||
</div> | ||
<div class="aa-ItemContentSubTitle ${item.type === 'lvl0' ? 'hidden' : ''}"> | ||
${components.Highlight({ | ||
hit : item, | ||
attribute: ['hierarchy', item.type], | ||
})} | ||
</div> | ||
<div class="aa-ItemContentDescription"> | ||
${components.Snippet({ | ||
hit : item, | ||
attribute: 'description', | ||
})} | ||
</div> | ||
</div> | ||
</div> | ||
</a>`; | ||
}, | ||
}, | ||
}; | ||
} | ||
autocomplete({ | ||
container: '#algolia-search', | ||
placeholder, | ||
getSources({query}) { | ||
return [ | ||
searchQuery(searchClient, query, searchScope) | ||
] | ||
} | ||
}); | ||
} | ||
</script> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/algoliasearch-lite.umd.js" | ||
integrity="sha256-b2n6oSgG4C1stMT/yc/ChGszs9EY/Mhs6oltEjQbFCQ=" crossorigin="anonymous"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/@algolia/[email protected]" onload="initSearchBar()"></script> |