homepage/themes/custom/static/js/search.js

35 lines
873 B
JavaScript
Raw Normal View History

2021-11-01 12:06:58 +01:00
/*
Some JavaScript for search, Aurore 2021
*/
new autoComplete({
data: {
src: async () => {
const source = await fetch(indexUrl);
const data = await source.json();
return data;
},
key: ["title", "content"],
cache: true
},
highlight: true,
resultsList: {
render: true
},
resultItem: {
content: (data, source) => {
found = data.match.match(/([^\s]*.{0,32}<span.*>.{0,32}[^\s]*)/);
if (found) {
source.innerHTML = "<b>" + data.value.title + "</b> : " + found[1];
} else {
// erdnaxe missed his regex...
console.log(data.match);
}
}
},
onSelection: feedback => {
// Go to page
window.location.href = feedback.selection.value.uri;
}
});