Switch themes to minimo

This commit is contained in:
Dave Gallant
2021-09-06 11:55:05 -04:00
parent 75f9797c91
commit 4ff7aec7c1
302 changed files with 17841 additions and 607 deletions

View File

@@ -0,0 +1,47 @@
import algoliasearch from 'algoliasearch/lite'
import {
appendResults,
getUrlSearchParam,
setSearchingIndicator
} from './helpers'
const { appId, indexName, searchApiKey } = window.algolia
const client = algoliasearch(appId, searchApiKey)
const index = client.initIndex(
`${indexName}${window.location.pathname.replace('/search/', '')}`
)
const doSearch = (term, resultsBlock) => {
setSearchingIndicator(resultsBlock)
if (!term) {
appendResults([], resultsBlock)
} else {
index.search(
term,
{ attributesToRetrieve: ['title', 'href'], hitsPerPage: 10 },
(err, content) => {
if (err) console.error(err)
else appendResults(content.hits, resultsBlock)
}
)
}
}
const searchForm = document.getElementById('search-form')
const searchInputBox = document.getElementById('search-term')
const resultsBlock = document.getElementById('search-results')
let term = getUrlSearchParam('q')
searchInputBox.value = term
searchInputBox.focus()
doSearch(term, resultsBlock)
searchForm.addEventListener('submit', e => {
e.preventDefault()
doSearch(searchInputBox.value, resultsBlock)
})