/************************************************* * Academic * https://github.com/gcushen/hugo-academic * * Algolia based search algorithm. **************************************************/ if ((typeof instantsearch === 'function') && $('#search-box').length) { function getTemplate(templateName) { return document.querySelector(`#${templateName}-template`).innerHTML; } const options = { appId: algoliaConfig.appId, apiKey: algoliaConfig.apiKey, indexName: algoliaConfig.indexName, routing: true, searchParameters: { hitsPerPage: 10 }, searchFunction: function (helper) { let searchResults = document.querySelector('#search-hits') if (helper.state.query === '') { searchResults.style.display = 'none'; return; } helper.search(); searchResults.style.display = 'block'; } }; const search = instantsearch(options); // Initialize search box. search.addWidget( instantsearch.widgets.searchBox({ container: '#search-box', autofocus: false, reset: true, poweredBy: algoliaConfig.poweredBy, placeholder: i18n.placeholder }) ); // Initialize search results. search.addWidget( instantsearch.widgets.infiniteHits({ container: '#search-hits', escapeHits: true, templates: { empty: '