From e0d872196902f5e4514d55deb5f81d6385ba3a1e Mon Sep 17 00:00:00 2001 From: scosman Date: Sun, 28 Jul 2024 17:57:47 -0400 Subject: [PATCH] Fix the search: now searched entire document --- src/lib/build_index.ts | 19 ++++++++++++++++--- src/routes/(marketing)/search/+page.svelte | 3 ++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/lib/build_index.ts b/src/lib/build_index.ts index 72fec70d..a0be791d 100644 --- a/src/lib/build_index.ts +++ b/src/lib/build_index.ts @@ -5,6 +5,8 @@ import { convert } from "html-to-text" import JSDOM from "jsdom" import Fuse from "fuse.js" +const excludePaths = ["/search"] + export async function buildSearchIndex() { const indexData = [] @@ -15,13 +17,24 @@ export async function buildSearchIndex() { const allFiles = glob.sync(path.join(pagesPath, "**/*.html")) for (const file of allFiles) { try { - // read the file - const data = fs.readFileSync(file, "utf8") - const plaintext = convert(data) const webPath = file .replace(pagesPath, "") .replace("/index.html", "") .replace(".html", "") + + // check if path is excluded + if (excludePaths.includes(webPath)) { + continue + } + + // read the file + const data = fs.readFileSync(file, "utf8") + const plaintext = convert(data, { + selectors: [ + { selector: "a", options: { ignoreHref: true, linkBrackets: false } }, + { selector: "img", format: "skip" }, + ], + }) const dom = new JSDOM.JSDOM(data) const title = dom.window.document.querySelector("title")?.innerHTML const description = dom.window.document diff --git a/src/routes/(marketing)/search/+page.svelte b/src/routes/(marketing)/search/+page.svelte index ec0d3e6b..354c84a2 100644 --- a/src/routes/(marketing)/search/+page.svelte +++ b/src/routes/(marketing)/search/+page.svelte @@ -7,7 +7,8 @@ const fuseOptions = { keys: ["title", "description", "body"], - //threshold: 0.1, + ignoreLocation: true, + threshold: 0.3, } let fuse: Fuse | undefined