Skip to content

Commit

Permalink
search improved
Browse files Browse the repository at this point in the history
  • Loading branch information
HYP3R00T committed Aug 9, 2024
1 parent 1e3b4af commit 40778b4
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/components/core/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,18 @@ import { Search as SearchIcon } from "lucide-react";

import type { DocsEntry } from "@/lib/types";
import { capitalizeFirstLetter } from "@/lib/utils";
import { menu_items } from "config";

function extractHeaders(body: string): string[] {
const headers = [];
const lines = body.split("\n");
for (const line of lines) {
const match = line.match(/^(#{1,6})\s+(.*)/);
if (match) {
headers.push(match[2]);
}
}
return headers;
}

const docs: DocsEntry[] = await getCollection("docs");

Expand Down Expand Up @@ -50,6 +61,11 @@ const options: IFuseOptions<DocsEntry> = {
weight: 1.5,
getFn: (docs: DocsEntry) => docs.data.tags.join(" ") || "",
},
{
name: "headers",
weight: 2,
getFn: (docs: DocsEntry) => extractHeaders(docs.body).join(" "),
},
],
};

Expand All @@ -74,8 +90,6 @@ export function Search() {
return () => document.removeEventListener("keydown", down);
}, []);

console.log(results);

return (
<div className="">
<Dialog open={open} onOpenChange={setOpen}>
Expand Down

0 comments on commit 40778b4

Please sign in to comment.