Skip to content

Commit 6001da5

Browse files
committed
Support Nextjs Doc
1 parent 8b9280a commit 6001da5

File tree

13 files changed

+190
-31
lines changed

13 files changed

+190
-31
lines changed

.gitignore

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
1-
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2-
3-
# dependencies
1+
# deps
42
/node_modules
53

6-
# next.js
4+
# generated content
5+
.contentlayer
6+
.content-collections
7+
.source
8+
9+
# test & build
10+
/coverage
711
/.next/
812
/out/
9-
10-
# production
1113
/build
14+
*.tsbuildinfo
1215

13-
# debug
16+
# misc
17+
.DS_Store
18+
*.pem
19+
/.pnp
20+
.pnp.js
1421
npm-debug.log*
1522
yarn-debug.log*
1623
yarn-error.log*
17-
.pnpm-debug.log*
1824

19-
# env files
20-
.env*
21-
22-
# vercel
25+
# others
26+
.env*.local
2327
.vercel
24-
25-
# typescript
26-
*.tsbuildinfo
2728
next-env.d.ts

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
# MCP
2+
https://fumadocs.vercel.app/

app/docs/[[...slug]]/page.tsx

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { source } from '@/lib/source';
2+
import {
3+
DocsPage,
4+
DocsBody,
5+
DocsDescription,
6+
DocsTitle,
7+
} from 'fumadocs-ui/page';
8+
import { notFound } from 'next/navigation';
9+
import defaultMdxComponents from 'fumadocs-ui/mdx';
10+
11+
export default async function Page(props: {
12+
params: Promise<{ slug?: string[] }>;
13+
}) {
14+
const params = await props.params;
15+
const page = source.getPage(params.slug);
16+
if (!page) notFound();
17+
18+
const MDX = page.data.body;
19+
20+
return (
21+
<DocsPage toc={page.data.toc} full={page.data.full}>
22+
<DocsTitle>{page.data.title}</DocsTitle>
23+
<DocsDescription>{page.data.description}</DocsDescription>
24+
<DocsBody>
25+
<MDX components={{ ...defaultMdxComponents }} />
26+
</DocsBody>
27+
</DocsPage>
28+
);
29+
}
30+
31+
export async function generateStaticParams() {
32+
return source.generateParams();
33+
}
34+
35+
export async function generateMetadata(props: {
36+
params: Promise<{ slug?: string[] }>;
37+
}) {
38+
const params = await props.params;
39+
const page = source.getPage(params.slug);
40+
if (!page) notFound();
41+
42+
return {
43+
title: page.data.title,
44+
description: page.data.description,
45+
};
46+
}

app/docs/layout.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { DocsLayout } from 'fumadocs-ui/layouts/docs';
2+
import type { ReactNode } from 'react';
3+
import { baseOptions } from '@/app/layout.config';
4+
import { source } from '@/lib/source';
5+
6+
export default function Layout({ children }: { children: ReactNode }) {
7+
return (
8+
<DocsLayout tree={source.pageTree} {...baseOptions}>
9+
{children}
10+
</DocsLayout>
11+
);
12+
}

app/layout.config.tsx

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import type { BaseLayoutProps } from 'fumadocs-ui/layouts/shared';
2+
3+
/**
4+
* Shared layout configurations
5+
*
6+
* you can customise layouts individually from:
7+
* Home Layout: app/(home)/layout.tsx
8+
* Docs Layout: app/docs/layout.tsx
9+
*/
10+
export const baseOptions: BaseLayoutProps = {
11+
nav: {
12+
title: (
13+
<>
14+
<svg
15+
width="24"
16+
height="24"
17+
xmlns="http://www.w3.org/2000/svg"
18+
aria-label="Logo"
19+
>
20+
<circle cx={12} cy={12} r={12} fill="currentColor" />
21+
</svg>
22+
My App
23+
</>
24+
),
25+
},
26+
links: [
27+
{
28+
text: 'Documentation',
29+
url: '/docs',
30+
active: 'nested-url',
31+
},
32+
],
33+
};

app/layout.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type React from "react"
22
import type { Metadata } from "next"
33
import { Inter } from "next/font/google"
44
import "./globals.css"
5-
5+
import { RootProvider } from 'fumadocs-ui/provider';
66
const inter = Inter({ subsets: ["latin"] })
77

88
export const metadata: Metadata = {
@@ -18,7 +18,15 @@ export default function RootLayout({
1818
}>) {
1919
return (
2020
<html lang="en">
21-
<body className={inter.className}>{children}</body>
21+
<body className={inter.className}>
22+
<RootProvider search={{
23+
options: {
24+
type: 'static',
25+
},
26+
}}>
27+
{children}
28+
</RootProvider>
29+
</body>
2230
</html>
2331
)
2432
}

app/page.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ export default function Home() {
2929
Compatible Tools
3030
</Link>
3131
<Link
32-
href="#docs"
32+
href="/docs"
3333
className="flex items-center text-sm font-medium text-muted-foreground transition-colors hover:text-primary"
3434
>
35-
Documentation
35+
Docs
3636
</Link>
3737
</nav>
3838
</div>
@@ -289,7 +289,7 @@ export default function Home() {
289289
</section>
290290

291291
{/* Documentation Section */}
292-
<section id="docs" className="w-full py-12 md:py-24 lg:py-32 gradient-bg">
292+
<section id="docs" className="w-full py-12 md:py-24 lg:py-32 gradient-bg" >
293293
<div className="container px-4 md:px-6">
294294
<div className="flex flex-col items-center justify-center space-y-4 text-center">
295295
<div className="space-y-2">

content/docs/index.mdx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
title: Hello World
3+
description: Your first document
4+
---
5+
6+
Welcome to the docs! You can start writing documents in `/content/docs`.
7+
8+
## What is Next?
9+
10+
<Cards>
11+
<Card title="Learn more about Next.js" href="https://nextjs.org/docs" />
12+
<Card title="Learn more about Fumadocs" href="https://fumadocs.vercel.app" />
13+
</Cards>

content/docs/test.mdx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
title: Components
3+
description: Components
4+
---
5+
6+
## Code Block
7+
8+
```js
9+
console.log('Hello World');
10+
```
11+
12+
## Cards
13+
14+
<Cards>
15+
<Card title="Learn more about Next.js" href="https://nextjs.org/docs" />
16+
<Card title="Learn more about Fumadocs" href="https://fumadocs.vercel.app" />
17+
</Cards>

lib/source.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { docs } from '@/.source';
2+
import { loader } from 'fumadocs-core/source';
3+
4+
export const source = loader({
5+
baseUrl: '/docs',
6+
source: docs.toFumadocsSource(),
7+
});

0 commit comments

Comments
 (0)