Skip to content

Commit

Permalink
docs: init new docs package (#422)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yonom authored Jul 7, 2024
1 parent f981053 commit 502d6c5
Show file tree
Hide file tree
Showing 18 changed files with 941 additions and 9 deletions.
28 changes: 28 additions & 0 deletions apps/docs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# deps
/node_modules

# generated content
.map.ts
.contentlayer
.content-collections

# test & build
/coverage
/.next/
/out/
/build
*.tsbuildinfo

# misc
.DS_Store
*.pem
/.pnp
.pnp.js
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# others
.env*.local
.vercel
next-env.d.ts
11 changes: 11 additions & 0 deletions apps/docs/app/api/search/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { getPages } from '@/app/source';
import { createSearchAPI } from 'fumadocs-core/search/server';

export const { GET } = createSearchAPI('advanced', {
indexes: getPages().map((page) => ({
title: page.data.title,
structuredData: page.data.exports.structuredData,
id: page.url,
url: page.url,
})),
});
44 changes: 44 additions & 0 deletions apps/docs/app/docs/[[...slug]]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { getPage, getPages } from '@/app/source';
import type { Metadata } from 'next';
import { DocsPage, DocsBody } from 'fumadocs-ui/page';
import { notFound } from 'next/navigation';

export default async function Page({
params,
}: {
params: { slug?: string[] };
}) {
const page = getPage(params.slug);

if (page == null) {
notFound();
}

const MDX = page.data.exports.default;

return (
<DocsPage toc={page.data.exports.toc} full={page.data.full}>
<DocsBody>
<h1>{page.data.title}</h1>
<MDX />
</DocsBody>
</DocsPage>
);
}

export async function generateStaticParams() {
return getPages().map((page) => ({
slug: page.slugs,
}));
}

export function generateMetadata({ params }: { params: { slug?: string[] } }) {
const page = getPage(params.slug);

if (page == null) notFound();

return {
title: page.data.title,
description: page.data.description,
} satisfies Metadata;
}
7 changes: 7 additions & 0 deletions apps/docs/app/docs/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { DocsLayout } from 'fumadocs-ui/layout';
import type { ReactNode } from 'react';
import { docsOptions } from '../layout.config';

export default function Layout({ children }: { children: ReactNode }) {
return <DocsLayout {...docsOptions}>{children}</DocsLayout>;
}
3 changes: 3 additions & 0 deletions apps/docs/app/global.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
22 changes: 22 additions & 0 deletions apps/docs/app/layout.config.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { type BaseLayoutProps, type DocsLayoutProps } from 'fumadocs-ui/layout';
import { pageTree } from '@/app/source';

// shared configuration
export const baseOptions: BaseLayoutProps = {
nav: {
title: 'My App',
},
links: [
{
text: 'Documentation',
url: '/docs',
active: 'nested-url',
},
],
};

// docs layout configuration
export const docsOptions: DocsLayoutProps = {
...baseOptions,
tree: pageTree,
};
15 changes: 15 additions & 0 deletions apps/docs/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import "./global.css";
import { RootProvider } from "fumadocs-ui/provider";
import type { ReactNode } from "react";
import { GeistSans } from "geist/font/sans";
import { GeistMono } from "geist/font/mono";

export default function Layout({ children }: { children: ReactNode }) {
return (
<html lang="en" className={GeistSans.className} suppressHydrationWarning>
<body>
<RootProvider>{children}</RootProvider>
</body>
</html>
);
}
16 changes: 16 additions & 0 deletions apps/docs/app/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import Link from 'next/link';

export default function HomePage() {
return (
<main className="flex h-screen flex-col justify-center text-center">
<h1 className="mb-4 text-2xl font-bold">Hello World</h1>
<p className="text-muted-foreground">
You can open{' '}
<Link href="/docs" className="text-foreground font-semibold underline">
/docs
</Link>{' '}
and see the documentation.
</p>
</main>
);
}
9 changes: 9 additions & 0 deletions apps/docs/app/source.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { map } from '@/.map';
import { createMDXSource } from 'fumadocs-mdx';
import { loader } from 'fumadocs-core/source';

export const { getPage, getPages, pageTree } = loader({
baseUrl: '/docs',
rootDir: 'docs',
source: createMDXSource(map),
});
13 changes: 13 additions & 0 deletions apps/docs/content/docs/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
title: Hello World
description: Your first document
---

Welcome to the docs! You can start writing documents in `/content/docs`.

## What is Next?

<Cards>
<Card title="Learn more about Next.js" href="https://nextjs.org/docs" />
<Card title="Learn more about Fumadocs" href="https://fumadocs.vercel.app" />
</Cards>
17 changes: 17 additions & 0 deletions apps/docs/content/docs/test.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
title: Components
description: Components
---

## Code Block

```js
console.log('Hello World');
```

## Cards

<Cards>
<Card title="Learn more about Next.js" href="https://nextjs.org/docs" />
<Card title="Learn more about Fumadocs" href="https://fumadocs.vercel.app" />
</Cards>
9 changes: 9 additions & 0 deletions apps/docs/mdx-components.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type { MDXComponents } from 'mdx/types';
import defaultComponents from 'fumadocs-ui/mdx';

export function useMDXComponents(components: MDXComponents): MDXComponents {
return {
...defaultComponents,
...components,
};
}
8 changes: 8 additions & 0 deletions apps/docs/next.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import createMDX from "fumadocs-mdx/config";

const withMDX = createMDX();

/** @type {import('next').NextConfig} */
const config = {};

export default withMDX(config);
28 changes: 28 additions & 0 deletions apps/docs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "docs",
"version": "0.0.0",
"private": true,
"scripts": {
"build": "next build",
"dev": "next dev",
"start": "next start"
},
"dependencies": {
"fumadocs-core": "12.4.1",
"fumadocs-mdx": "8.2.33",
"fumadocs-ui": "12.4.1",
"geist": "^1.3.0",
"next": "^14.2.4",
"react": "^18.3.1",
"react-dom": "^18.3.1"
},
"devDependencies": {
"@types/mdx": "^2.0.13",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"autoprefixer": "^10.4.19",
"postcss": "^8.4.39",
"tailwindcss": "^3.4.4",
"typescript": "^5.5.3"
}
}
6 changes: 6 additions & 0 deletions apps/docs/postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
};
13 changes: 13 additions & 0 deletions apps/docs/tailwind.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { createPreset } from 'fumadocs-ui/tailwind-plugin';

/** @type {import('tailwindcss').Config} */
export default {
content: [
'./components/**/*.{ts,tsx}',
'./app/**/*.{ts,tsx}',
'./content/**/*.{md,mdx}',
'./mdx-components.{ts,tsx}',
'./node_modules/fumadocs-ui/dist/**/*.js',
],
presets: [createPreset()],
};
29 changes: 29 additions & 0 deletions apps/docs/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"compilerOptions": {
"baseUrl": ".",
"target": "ESNext",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"paths": {
"@/*": ["./*"]
},
"plugins": [
{
"name": "next"
}
]
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
}
Loading

0 comments on commit 502d6c5

Please sign in to comment.