Skip to content

Commit 18c8140

Browse files
committed
init
1 parent df64ac5 commit 18c8140

File tree

8 files changed

+12625
-6
lines changed

8 files changed

+12625
-6
lines changed

js/algolia/index.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { html } from 'htm/preact';
2+
import algoliasearch from 'algoliasearch/lite';
3+
import { autocomplete, getAlgoliaHits } from '@algolia/autocomplete-js';
4+
5+
// import '@algolia/autocomplete-theme-classic';
6+
7+
const searchClient = algoliasearch(
8+
'UINQ2M4D9S',
9+
'636b6d9e2dfb207e89ea7344859848f9'
10+
);
11+
12+
autocomplete({
13+
container: '#autocomplete',
14+
placeholder: 'Search for the Segment documentation (press / to focus)',
15+
debug: true,
16+
getSources( {query} ) {
17+
return [
18+
{
19+
sourceId: 'articles',
20+
getItems() {
21+
return getAlgoliaHits({
22+
searchClient,
23+
queries: [
24+
{
25+
indexName: 'segment-docs',
26+
query,
27+
params: {
28+
hitsPerPage: 5
29+
},
30+
},
31+
],
32+
});
33+
},
34+
templates: {
35+
item({ item }){
36+
if (item.anchor != null) {
37+
var anchorLink = "#" + item.anchor;
38+
} else {
39+
var anchorLink = "";
40+
}
41+
return html `<a class="aa-link" href="/docs${item.url}${anchorLink}">
42+
<p class="aa-title" >${item.title}</h3>
43+
<p class="aa-heading">${item.headings.join(' >')}</p>
44+
<p class="aa-content">${item.content}</p></a>
45+
`;
46+
},
47+
noResults() {
48+
return 'no results';
49+
}
50+
}
51+
}
52+
];
53+
},
54+
});

js/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import sideMenu from './side-menu'
1919
import tracking from './tracking'
2020
import searchBar from './search-bar'
2121
import glightbox from './glightbox'
22+
import autocomplete from './algolia'
2223
feedback()
2324
accordion()
2425
accordionGroup()
@@ -40,3 +41,4 @@ sideMenu()
4041
tracking()
4142
searchBar()
4243
glightbox()
44+
autocomplete()

0 commit comments

Comments
 (0)