Skip to content

Commit 0996d44

Browse files
committed
improvements and install algolia
1 parent 05bf1bd commit 0996d44

7 files changed

Lines changed: 281 additions & 4 deletions

File tree

app/api/algolia/route.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { source } from '@/lib/source';
2+
import { sync } from 'fumadocs-core/search/algolia';
3+
import { algoliasearch } from 'algoliasearch';
4+
5+
export const runtime = 'nodejs';
6+
// Disable caching so re-index always runs fresh
7+
export const dynamic = 'force-dynamic';
8+
9+
export async function GET(req: Request) {
10+
const token = new URL(req.url).searchParams.get('token');
11+
if (token !== process.env.ALGOLIA_INDEX_SECRET) {
12+
return Response.json({ error: 'Unauthorized' }, { status: 401 });
13+
}
14+
15+
const client = algoliasearch(
16+
process.env.NEXT_PUBLIC_ALGOLIA_APP_ID!,
17+
process.env.ALGOLIA_ADMIN_KEY!,
18+
);
19+
20+
const pages = source.getPages();
21+
22+
await sync(client, {
23+
indexName: process.env.NEXT_PUBLIC_ALGOLIA_INDEX!,
24+
documents: pages.map((page) => ({
25+
_id: page.url,
26+
title: page.data.title,
27+
description: page.data.description,
28+
url: page.url,
29+
structured: page.data.structuredData,
30+
breadcrumbs: [],
31+
})),
32+
});
33+
34+
return Response.json({ ok: true, indexed: pages.length });
35+
}

app/globals.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@
8282
box-shadow: none !important;
8383
}
8484

85-
/* Remove max-height on code blocks inside API example/request panels so content doesn't scroll */
85+
/* Cap max-height on code blocks inside API example/request panels */
8686
[data-api-requests] .fd-scroll-container {
87-
max-height: none !important;
87+
max-height: 1200px !important;
8888
}
8989

9090
/* Docusaurus-style callouts: transparent colorized backgrounds */

app/layout.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import { RootProvider } from 'fumadocs-ui/provider/next';
2+
import { AlgoliaDialog } from '@/components/search';
23
import type { ReactNode } from 'react';
34
import './globals.css';
45

56
export default function Layout({ children }: { children: ReactNode }) {
67
return (
78
<html lang="en" suppressHydrationWarning>
89
<body className="flex min-h-screen flex-col">
9-
<RootProvider>{children}</RootProvider>
10+
<RootProvider search={{ SearchDialog: AlgoliaDialog }}>
11+
{children}
12+
</RootProvider>
1013
</body>
1114
</html>
1215
);

components/api-page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export const APIPage = createAPIPage(openapi, {
3333
{slots.responses}
3434
{slots.callbacks}
3535
</>,
36-
slots.apiExample,
36+
<div data-api-requests>{slots.apiExample}</div>,
3737
);
3838
},
3939
renderWebhookLayout(slots) {

components/search.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
'use client';
2+
3+
import AlgoliaSearchDialog from 'fumadocs-ui/components/dialog/search-algolia';
4+
import { liteClient } from 'algoliasearch/lite';
5+
import type { SharedProps } from 'fumadocs-ui/contexts/search';
6+
7+
const searchOptions = {
8+
indexName: process.env.NEXT_PUBLIC_ALGOLIA_INDEX!,
9+
client: liteClient(
10+
process.env.NEXT_PUBLIC_ALGOLIA_APP_ID!,
11+
process.env.NEXT_PUBLIC_ALGOLIA_SEARCH_KEY!,
12+
),
13+
};
14+
15+
export function AlgoliaDialog(props: SharedProps) {
16+
return <AlgoliaSearchDialog searchOptions={searchOptions} {...props} />;
17+
}

package-lock.json

Lines changed: 221 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
},
1212
"dependencies": {
1313
"@types/mdx": "^2",
14+
"algoliasearch": "^5.49.2",
1415
"fumadocs-core": "latest",
1516
"fumadocs-mdx": "latest",
1617
"fumadocs-openapi": "latest",

0 commit comments

Comments
 (0)