rework/lightweight #12

Merged
GauthierWebDev merged 106 commits from rework/lightweight into main 2025-04-21 16:27:38 +00:00
2 changed files with 34 additions and 27 deletions
Showing only changes of commit 8ed5451c37 - Show all commits

View File

@ -1,9 +0,0 @@
import { buildFlexSearch } from "@/services/FlexSearchService";
import { docCache } from "@/services/DocCache";
export const onSearch = async (query: string) => {
const docs = docCache.fetchDocs();
const search = buildFlexSearch(docs);
return search(query, 5);
};

View File

@ -8,9 +8,11 @@ import {
createEffect, createEffect,
createSignal, createSignal,
} from "solid-js"; } from "solid-js";
import { Dialog, DialogPanel } from "terracotta";
import { useDebounce } from "@/hooks/useDebounce";
import { Highlighter } from "solid-highlight-words"; import { Highlighter } from "solid-highlight-words";
import { useDebounce } from "@/hooks/useDebounce";
import { Dialog, DialogPanel } from "terracotta";
import { navigation } from "@/libs/navigation";
import { navigate } from "vike/client/router"; import { navigate } from "vike/client/router";
import { useId } from "@/hooks/useId"; import { useId } from "@/hooks/useId";
import clsx from "clsx"; import clsx from "clsx";
@ -127,6 +129,18 @@ function SearchResultItem(props: { result: SearchResult; query: string }) {
const { close } = useContext(SearchContext); const { close } = useContext(SearchContext);
const id = useId(); const id = useId();
const getHierarchy = (): string[] => {
const sectionTitle = navigation.find((section) => {
return section.links.find(
(link) => link.href === props.result.url.split("#")[0],
);
})?.title;
return [sectionTitle, props.result.pageTitle].filter(
(x): x is string => typeof x === "string",
);
};
return ( return (
<li <li
class="group block cursor-default rounded-lg px-3 py-2 aria-selected:bg-slate-100 hover:bg-slate-100" class="group block cursor-default rounded-lg px-3 py-2 aria-selected:bg-slate-100 hover:bg-slate-100"
@ -150,28 +164,30 @@ function SearchResultItem(props: { result: SearchResult; query: string }) {
> >
<HighlightQuery text={props.result.title} query={props.query} /> <HighlightQuery text={props.result.title} query={props.query} />
</div> </div>
{/* {props.result.length > 0 && ( {getHierarchy().length > 0 && (
<div <div
id={`${id}-hierarchy`} id={`${id}-hierarchy`}
aria-hidden="true" aria-hidden="true"
class="mt-0.5 truncate text-xs whitespace-nowrap text-slate-500 dark:text-slate-400" class="mt-0.5 truncate text-xs whitespace-nowrap text-slate-500 dark:text-slate-400"
> >
{hierarchy.map((item, itemIndex, items) => ( <For each={getHierarchy()}>
<Fragment key={itemIndex}> {(item, itemIndex) => (
<HighlightQuery text={item} query={query} /> <>
<HighlightQuery text={item} query={props.query} />
<span <span
class={ class={
itemIndex === items.length - 1 itemIndex() === getHierarchy().length - 1
? "sr-only" ? "sr-only"
: "mx-2 text-slate-300 dark:text-slate-700" : "mx-2 text-slate-300 dark:text-slate-700"
} }
> >
/ /
</span> </span>
</Fragment> </>
))} )}
</For>
</div> </div>
)} */} )}
</li> </li>
); );
} }