Skip to content

Commit 8ba2de7

Browse files
Merge pull request #16 from OpenZeppelin/chore/experimental-static
chore: experimental static build
2 parents 55c9a31 + 34e519c commit 8ba2de7

File tree

8 files changed

+79
-34
lines changed

8 files changed

+79
-34
lines changed

next.config.mjs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,8 @@ const withMDX = createMDX();
55
/** @type {import('next').NextConfig} */
66
const config = {
77
reactStrictMode: true,
8-
async rewrites() {
9-
return [
10-
{
11-
source: "/:path*.md",
12-
destination: "/llms.mdx/:path*",
13-
},
14-
];
15-
},
8+
output: "export",
9+
images: { unoptimized: true },
1610
};
1711

1812
export default withMDX(config);

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"dependencies": {
1818
"@fumadocs/mdx-remote": "^1.4.0",
1919
"@netlify/plugin-nextjs": "^5.13.1",
20+
"@orama/orama": "^3.1.13",
2021
"@radix-ui/react-collapsible": "^1.1.12",
2122
"@radix-ui/react-popover": "^1.1.15",
2223
"@radix-ui/react-presence": "^1.1.5",

pnpm-lock.yaml

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

src/app/api/search/route.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
1-
import { structure } from "fumadocs-core/mdx-plugins";
2-
import { createSearchAPI } from "fumadocs-core/search/server";
1+
import { createFromSource } from "fumadocs-core/search/server";
32
import { source } from "@/lib/source";
43

5-
export const { GET } = createSearchAPI("advanced", {
6-
language: "english",
7-
indexes: source.getPages().map((page) => ({
8-
title: page.data.title,
9-
description: page.data.description,
10-
url: page.url,
11-
id: page.url,
12-
structuredData: structure(page.data.content),
13-
})),
14-
});
4+
// statically cached
5+
export const revalidate = false;
6+
export const { staticGET: GET } = createFromSource(source);

src/app/layout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import "@/app/global.css";
2-
import { RootProvider } from "fumadocs-ui/provider";
32
import { Inter } from "next/font/google";
43
import type { ReactNode } from "react";
4+
import { Provider } from "./provider";
55

66
const inter = Inter({
77
subsets: ["latin"],
@@ -11,7 +11,7 @@ export default function Layout({ children }: { children: ReactNode }) {
1111
return (
1212
<html lang="en" className={inter.className} suppressHydrationWarning>
1313
<body className="flex flex-col min-h-screen">
14-
<RootProvider>{children}</RootProvider>
14+
<Provider>{children}</Provider>
1515
</body>
1616
</html>
1717
);

src/app/llms-full.txt/route.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/app/provider.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"use client";
2+
import { RootProvider } from "fumadocs-ui/provider";
3+
import type { ReactNode } from "react";
4+
import SearchDialog from "@/components/search";
5+
6+
export function Provider({ children }: { children: ReactNode }) {
7+
return (
8+
<RootProvider
9+
search={{
10+
SearchDialog,
11+
}}
12+
>
13+
{children}
14+
</RootProvider>
15+
);
16+
}

src/components/search.tsx

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
"use client";
2+
import { create } from "@orama/orama";
3+
import { useDocsSearch } from "fumadocs-core/search/client";
4+
import {
5+
SearchDialog,
6+
SearchDialogClose,
7+
SearchDialogContent,
8+
SearchDialogHeader,
9+
SearchDialogIcon,
10+
SearchDialogInput,
11+
SearchDialogList,
12+
SearchDialogOverlay,
13+
type SharedProps,
14+
} from "fumadocs-ui/components/dialog/search";
15+
import { useI18n } from "fumadocs-ui/contexts/i18n";
16+
17+
function initOrama() {
18+
return create({
19+
schema: { _: "string" },
20+
// https://docs.orama.com/docs/orama-js/supported-languages
21+
language: "english",
22+
});
23+
}
24+
25+
export default function DefaultSearchDialog(props: SharedProps) {
26+
const { locale } = useI18n(); // (optional) for i18n
27+
const { search, setSearch, query } = useDocsSearch({
28+
type: "static",
29+
initOrama,
30+
locale,
31+
});
32+
33+
return (
34+
<SearchDialog
35+
search={search}
36+
onSearchChange={setSearch}
37+
isLoading={query.isLoading}
38+
{...props}
39+
>
40+
<SearchDialogOverlay />
41+
<SearchDialogContent>
42+
<SearchDialogHeader>
43+
<SearchDialogIcon />
44+
<SearchDialogInput />
45+
<SearchDialogClose />
46+
</SearchDialogHeader>
47+
<SearchDialogList items={query.data !== "empty" ? query.data : null} />
48+
</SearchDialogContent>
49+
</SearchDialog>
50+
);
51+
}

0 commit comments

Comments
 (0)