-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
57 lines (47 loc) · 1.15 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
function init( appId, apiKey, index) {
// Get Algolia App ID from env
const ALGOLIA_APP_ID = appId;
// Get Aloglia API Key from env
const ALGOLIA_API_KEY = apiKey;
// Get Algolia Index from env
const ALGOLIA_INDEX = index;
// Initialize InstantSearch
const search = instantsearch({
indexName: ALGOLIA_INDEX,
searchClient: algoliasearch(ALGOLIA_APP_ID, ALGOLIA_API_KEY),
});
// Add search box
search.addWidgets([
instantsearch.widgets.searchBox({
container: '#searchbox',
placeholder: 'Search for Engineers',
}),
]);
// Add hits widget
search.addWidgets([
instantsearch.widgets.hits({
container: '#hits',
templates: {
item: `
<div>
<h3>{{#helpers.highlight}}{ "attribute": "name" }{{/helpers.highlight}}</h3>
</div>
`,
},
}),
]);
search.start();
};
// On Document Ready with Vanilla JS
document.addEventListener('DOMContentLoaded', function() {
try {
// Get variables from env.
const appId = ALGOLIA_APP_ID;
const apiKey = ALGOLIA_API_KEY;
const index = ALGOLIA_INDEX;
// Initialize InstantSearch
init(appId, apiKey, index);
} catch (error) {
console.error('Error:', error);
}
});