Added tags to search result, search no long matches the project tags (the ones used for filtering) and implemented author page that show up on search.

This commit is contained in:
天クマ 2025-10-25 19:51:28 -03:00
commit e54f2336db
27 changed files with 244 additions and 89 deletions

View file

@ -3,22 +3,36 @@ fetch('/search_index.json')
.then(data => {
const idx = elasticlunr.Index.load(data);
const docs = idx.documentStore.docs;
console.log(Object.values(docs)[0])
const searchInput = document.getElementById('search');
const out = document.getElementById('searchResults');
const filterSelect = document.getElementById('searchMode');
function runSearch(q, tags) {
return idx.search(q, { expand: true })
.map(r => docs[r.ref] )
.filter(d => tags === 'all' || d.tags.includes(tags));
function runSearch(q, tags = 'all') {
let result = idx.search(q, { expand: true }).map(r => docs[r.ref] )
if (tags === 'all') {
return result;
}
result = result.filter(d => tags === 'all' || d.tags.includes(tags));
return result;
}
function render(doc) {
return `<div>
<img class="searchItemImage" src="${doc.image}">
<a class="searchItemTitle" href="${doc.url}">${doc.title}</a>
console.log(doc.imageq)
let tagsHTML = "";
console.log(doc.tags)
doc.tags.forEach(tag => {
tagsHTML += `<div class="tag-${tag}">${tag}</div>`
});
return `<div class="searchItem">
<p>${doc.image ? `<img float=left class="searchItemImage" src="${doc.image}">` : ''} <a class="searchItemTitle" href="${doc.url}">${doc.title}</a>${doc.author ? ` by <a href="/authors/${doc.author}">${doc.author}</a>` : ''}</p>
<p class="searchItemDescription">${doc.subtitle}</p>
<div class="searchItemTagHolder">
${tagsHTML}
</div>
</div>`;
}