diff --git a/src/app/(home)/layout.tsx b/src/app/(home)/layout.tsx index 85beb85..b8b904e 100644 --- a/src/app/(home)/layout.tsx +++ b/src/app/(home)/layout.tsx @@ -2,9 +2,5 @@ import { HomeLayout } from "fumadocs-ui/layouts/home"; import { baseOptions } from "@/lib/layout.shared"; export default function Layout({ children }: LayoutProps<"/">) { - return ( - - {children} - - ); + return {children}; } diff --git a/src/app/api/search-all/route.ts b/src/app/api/search-all/route.ts new file mode 100644 index 0000000..6b990c9 --- /dev/null +++ b/src/app/api/search-all/route.ts @@ -0,0 +1,53 @@ +import { getRepoMeta, getSource, repoIds } from "@/lib/source"; +import { createSearchAPI, type AdvancedIndex } from "fumadocs-core/search/server"; + +// Combined cross-repo search index for the home page + +export const revalidate = false; + +interface SearchPageData { + title?: string; + description?: string; + structuredData?: unknown; + load?: () => Promise<{ structuredData: unknown }>; +} + +async function buildIndexes(): Promise { + const indexes: AdvancedIndex[] = []; + + for (const repoId of repoIds) { + const source = getSource(repoId); + if (!source) continue; + const repoName = getRepoMeta(repoId)?.name ?? repoId; + + const pages = source.getPages() as { data: SearchPageData; url: string }[]; + for (const page of pages) { + let structuredData = page.data.structuredData; + if (typeof structuredData === "function") structuredData = await structuredData(); + if (!structuredData && typeof page.data.load === "function") { + structuredData = (await page.data.load()).structuredData; + } + if (!structuredData) continue; + + indexes.push({ + id: page.url, + url: page.url, + title: page.data.title ?? page.url, + description: page.data.description, + breadcrumbs: [repoName], + tag: repoId, + structuredData: structuredData as never, + }); + } + } + + return indexes; +} + +export async function GET() { + const { staticGET } = createSearchAPI("advanced", { + indexes: buildIndexes, + language: "english", + }); + return staticGET(); +} diff --git a/src/app/global.css b/src/app/global.css index b88fee4..22f8c68 100644 --- a/src/app/global.css +++ b/src/app/global.css @@ -68,3 +68,14 @@ body { "sidebar . toc-popover toc ." "sidebar . main toc ." !important; } + +#nd-home-layout #nd-nav [class*="max-w-(--fd-layout-width)"] { + max-width: none; + margin-inline-start: 0; + padding-inline-start: 1.5625rem; +} + +#nd-sidebar a[href="/"] { + align-self: flex-start; + margin-top: -0.625rem; +} diff --git a/src/components/search.tsx b/src/components/search.tsx index def2736..922a589 100644 --- a/src/components/search.tsx +++ b/src/components/search.tsx @@ -32,7 +32,7 @@ export default function DefaultSearchDialog(props: SharedProps) { client: oramaStaticClient({ initOrama, locale, - from: repo ? `/api/search/${repo}` : undefined, + from: repo ? `/api/search/${repo}` : "/api/search-all", }), delayMs: 100, });