37 lines
No EOL
945 B
HTML
37 lines
No EOL
945 B
HTML
---
|
|
layout: "base.njk"
|
|
---
|
|
|
|
<input type="text" id="search" placeholder="Search..." />
|
|
<ul id="results"></ul>
|
|
|
|
<script
|
|
type="text/javascript"
|
|
src="https://cdnjs.cloudflare.com/ajax/libs/elasticlunr/0.9.6/elasticlunr.min.js"
|
|
></script>
|
|
<script>
|
|
fetch('/search_index.json')
|
|
.then(r => r.json())
|
|
.then(data => {
|
|
const idx = elasticlunr.Index.load(data);
|
|
const docs = idx.documentStore.docs;
|
|
const searchInput = document.getElementById('search');
|
|
const out = document.getElementById('results');
|
|
|
|
searchInput.addEventListener('input', function () {
|
|
const q = this.value.trim();
|
|
if (!q) {
|
|
out.innerHTML = '';
|
|
return;
|
|
}
|
|
|
|
const items = idx.search(q).map(r => {
|
|
const doc = docs[r.ref];
|
|
return `<li><a href="${doc.url}">${doc.title}</a></li>`;
|
|
});
|
|
|
|
out.innerHTML = items.join('');
|
|
});
|
|
|
|
});
|
|
</script> |