Skip to content

Commit

Permalink
Fix the search: now searched entire document
Browse files Browse the repository at this point in the history
  • Loading branch information
scosman committed Jul 28, 2024
1 parent 4ed5142 commit e0d8721
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
19 changes: 16 additions & 3 deletions src/lib/build_index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []

Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/routes/(marketing)/search/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
const fuseOptions = {
keys: ["title", "description", "body"],
//threshold: 0.1,
ignoreLocation: true,
threshold: 0.3,
}
let fuse: Fuse<Result> | undefined
Expand Down

0 comments on commit e0d8721

Please sign in to comment.