Fix search
This commit is contained in:
parent
8176044338
commit
e58039d1ae
File diff suppressed because one or more lines are too long
|
@ -185,19 +185,21 @@ $(document).ready(() => {
|
||||||
$inputSearch.keyup(() => {
|
$inputSearch.keyup(() => {
|
||||||
if ($inputSearch.val().length > 0 && fuse) {
|
if ($inputSearch.val().length > 0 && fuse) {
|
||||||
const results = fuse.search($inputSearch.val())
|
const results = fuse.search($inputSearch.val())
|
||||||
|
const bestResults = results.filter((result) => {
|
||||||
|
if (result.score <= 0.5) {
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
let htmlString = ''
|
let htmlString = ''
|
||||||
|
|
||||||
if (results.length > 0) {
|
if (bestResults.length > 0) {
|
||||||
for (let i = 0, len = results.length; i < len; i++) {
|
for (let i = 0, len = bestResults.length; i < len; i++) {
|
||||||
if (results[i].score > 0.5) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
htmlString += `
|
htmlString += `
|
||||||
<article class="m-result">\
|
<article class="m-result">\
|
||||||
<a href="${results[i].item.url}" class="m-result__link">\
|
<a href="${bestResults[i].item.url}" class="m-result__link">\
|
||||||
<h3 class="m-result__title">${results[i].item.title}</h3>\
|
<h3 class="m-result__title">${bestResults[i].item.title}</h3>\
|
||||||
<span class="m-result__date">${formatDate(results[i].item.published_at)}</span>\
|
<span class="m-result__date">${formatDate(bestResults[i].item.published_at)}</span>\
|
||||||
</a>\
|
</a>\
|
||||||
</article>`
|
</article>`
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue