Skip to content

Commit fba1589

Browse files
authored
bug fixes for search (#826)
* add the home page to the default list of indexable pages - even though it's not in pages, it's not ‘unlisted’ - one can still opt out with index: false, as we do for this documentation * when the page title is undefined, replace with an emdash (avoids a crash when indexing untitled pages) * type safety (for title = a number)
1 parent 66881c0 commit fba1589

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/client/search.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ input.addEventListener("input", () => {
4343
function renderResult({id, score, title}, i) {
4444
return `<li data-score="${Math.min(5, Math.round(0.6 * score))}" class="observablehq-link${
4545
i === 0 ? ` ${activeClass}` : ""
46-
}"><a href="${escapeDoubleQuote(import.meta.resolve(`../${id}`))}">${escapeText(title)}</a></li>`;
46+
}"><a href="${escapeDoubleQuote(import.meta.resolve(`../${id}`))}">${escapeText(String(title ?? "—"))}</a></li>`;
4747
}
4848

4949
function escapeDoubleQuote(text) {

src/search.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export async function searchIndex(config: Config, effects = defaultEffects): Pro
3030
if (indexCache.has(config) && indexCache.get(config).freshUntil > +new Date()) return indexCache.get(config).json;
3131

3232
// Get all the listed pages (which are indexed by default)
33-
const pagePaths = new Set();
33+
const pagePaths = new Set(["/index"]);
3434
for (const p of pages) {
3535
if ("path" in p) pagePaths.add(p.path);
3636
else for (const {path} of p.pages) pagePaths.add(path);

0 commit comments

Comments
 (0)