diff --git a/apps/docs/app/api/search/route.ts b/apps/docs/app/api/search/route.ts index 7ba7e82..78135e7 100644 --- a/apps/docs/app/api/search/route.ts +++ b/apps/docs/app/api/search/route.ts @@ -1,7 +1,21 @@ import { source } from '@/lib/source'; import { createFromSource } from 'fumadocs-core/search/server'; +import type { InferPageType } from 'fumadocs-core/source'; export const { GET } = createFromSource(source, { // https://docs.orama.com/docs/orama-js/supported-languages language: 'english', + // Configure tag filter based on the first slug (core, cli, api) + buildIndex(page: InferPageType) { + const tag = page.slugs[0] || 'all'; + return { + title: page.data.title, + description: page.data.description, + url: page.url, + id: page.url, + structuredData: page.data.structuredData, + // Assign tag based on the first slug (core, cli, api) + tag, + } as any; + }, }); diff --git a/apps/docs/app/layout.tsx b/apps/docs/app/layout.tsx index 1228c52..f11afc4 100644 --- a/apps/docs/app/layout.tsx +++ b/apps/docs/app/layout.tsx @@ -3,6 +3,7 @@ import './global.css'; import { Inter } from 'next/font/google'; import type { Metadata } from 'next'; import { GoogleAnalytics } from '@next/third-parties/google'; +import SearchDialog from '@/components/SearchDialog'; const inter = Inter({ subsets: ['latin'], @@ -28,7 +29,13 @@ export default function Layout({ children }: LayoutProps<'/'>) { - {children} + + {children} + ); diff --git a/apps/docs/components/SearchDialog.tsx b/apps/docs/components/SearchDialog.tsx new file mode 100644 index 0000000..b3e70b9 --- /dev/null +++ b/apps/docs/components/SearchDialog.tsx @@ -0,0 +1,54 @@ +'use client'; + +import { + SearchDialog, + SearchDialogClose, + SearchDialogContent, + SearchDialogFooter, + SearchDialogHeader, + SearchDialogIcon, + SearchDialogInput, + SearchDialogList, + SearchDialogOverlay, + TagsList, + TagsListItem, + type SharedProps, +} from 'fumadocs-ui/components/dialog/search'; +import { useDocsSearch } from 'fumadocs-core/search/client'; +import { useState } from 'react'; + +export default function CustomSearchDialog(props: SharedProps) { + const [tag, setTag] = useState('all'); + // When tag is "all", don't filter by tag (pass undefined) + const { search, setSearch, query } = useDocsSearch({ + type: 'fetch', + tag: tag === 'all' ? undefined : tag, + }); + + return ( + + + + + + + + + + + + All + Core + CLI + API + + + + + ); +}