Skip to content

Commit

Permalink
Fix: Search
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanlelek committed May 2, 2024
1 parent 6c5770f commit 06757c3
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions app/core/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,31 @@ async function handler(query, config) {
const results = idx.search(query);

const searchResults = await Promise.all(
results.map((result) =>
processSearchResult(contentDir, config, query, result),
),
results.map(async (result) => {
const processed = await processSearchResult(
contentDir,
config,
query,
result,
);
return processed;
}),
);

return searchResults;
}

async function processSearchResult(contentDir, config, query, result) {
const page = await page_handler(contentDir + result.ref, config);
page.excerpt = page.excerpt.replace(
new RegExp(`(${query})`, 'gim'),
'<span class="search-query">$1</span>',
);

// Removed
// contentDir +
const page = await page_handler(result.ref, config);
// TODO: Improve handling
if (page && page.excerpt) {
page.excerpt = page.excerpt.replace(
new RegExp(`(${query})`, 'gim'),
'<span class="search-query">$1</span>',
);
}
return page;
}

Expand Down

0 comments on commit 06757c3

Please sign in to comment.