Skip to content

Commit

Permalink
Docs: Improve quick start experience
Browse files Browse the repository at this point in the history
  • Loading branch information
fuma-nama committed May 18, 2024
1 parent e3f28fd commit 2498124
Show file tree
Hide file tree
Showing 6 changed files with 213 additions and 162 deletions.
15 changes: 15 additions & 0 deletions apps/docs/content/docs/example/tailwind.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { createPreset } from 'fumadocs-ui/tailwind-plugin';

/** @type {import('tailwindcss').Config} */
export default {
darkMode: 'class',
presets: [createPreset()],
content: [
'./node_modules/fumadocs-ui/dist/**/*.js',

'./components/**/*.{ts,tsx}',
'./app/**/*.{ts,tsx}',
'./content/**/*.mdx',
'./mdx-components.tsx',
],
};
25 changes: 5 additions & 20 deletions apps/docs/content/docs/headless/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ App Router. It offers server-side functions and headless components.
- Additional utilities

<Callout title="Tip">
For beginners and normal usages, use [Fumadocs UI](/docs/ui).

Fumadocs Core can be used without Fumadocs UI, in other words, it's headless.

For beginners and normal usages, use [Fumadocs UI](/docs/ui).

</Callout>

```package-install
Expand All @@ -35,25 +39,6 @@ use Contentlayer with `fumadocs-core`.

A page tree refers to the structured data of all pages. It is essential for implementing a sidebar, or other navigation elements.

```js
export const tree = [
{
type: 'page',
name: 'Quick Start',
url: '/docs',
},
{
type: 'separator',
name: 'Guides',
},
{
type: 'page',
name: 'Example',
url: '/docs/example',
},
];
```

You can generate the tree using our built-in [Source API](/docs/headless/source-api), the adapter for your content source, or end up with
writing your own.

Expand Down
140 changes: 16 additions & 124 deletions apps/docs/content/docs/ui/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@ icon: Album

**Fumadocs** can be broken down into two parts: Core and UI.

Core handles most of the logic, from search functionality, MDX enhancement, to content source APIs for you to plug in your own **content source**.
**Core** handles most of the logic, from search functionality, to MDX plugins.

Fumadocs UI, as named, it is the official user interface for Fumadocs.
**Fumadocs UI**, as named, it is the official user interface for Fumadocs.

In this documentation, when we are calling Fumadocs UI, it refers to the entire framework.

> Fumadocs Core can be used without Fumadocs UI, in other words, it's headless.
### Terminology

For a better understanding of the docs, there are some common terminologies you should know:

**Content Source:** The source of your content, for example, Fumadocs MDX, MDXTS and ContentLayer are examples of content source.

**Page Tree:** A tree of all the pages, separators and folders. It is essential for navigation elements. See [Page Tree](/docs/headless/page-tree).

## Automatic Installation

Expand Down Expand Up @@ -52,119 +58,11 @@ bun create fumadocs-app

</InstallTabs>

## Manual Installation

Create a new Next.js application with `create-next-app`, and install required packages.

```package-install
fumadocs-ui fumadocs-core
```

### Configuration

You can choose a **content source** you prefer, such as ContentLayer and Fumadocs MDX.

There is a list of supported sources:

- [Setup Fumadocs MDX](/docs/mdx)
- [Setup Contentlayer](/docs/headless/contentlayer)

You have to configure the library correctly following their setup guide before continuing.
It will initialize a new fumadocs app, now you can start hacking!

### Styles
### Enjoy!

You can import the pre-built stylesheet in the root layout.

```ts
import 'fumadocs-ui/style.css';
```

For Tailwind CSS projects, use [the official plugin](/docs/ui/theme) instead.

> It doesn't come with a default font, you may choose one from `next/font`.
### Root Layout

Wrap the entire application inside [Root Provider](/docs/ui/blocks/root-provider).

```tsx
import { RootProvider } from 'fumadocs-ui/provider';
import type { ReactNode } from 'react';

export default function RootLayout({ children }: { children: ReactNode }) {
return (
<html lang="en">
<body>
<RootProvider>{children}</RootProvider>
</body>
</html>
);
}
```

### Layout

Create a new catch-all route `/app/docs/[[..slugs]]` for our docs, and give it a proper layout.

```tsx title="app/docs/layout.tsx"
import { DocsLayout } from 'fumadocs-ui/layout';
import { pageTree } from '@/source';
import type { ReactNode } from 'react';

export default function RootDocsLayout({ children }: { children: ReactNode }) {
return (
<DocsLayout tree={pageTree} nav={{ title: 'My App' }}>
{children}
</DocsLayout>
);
}
```

> `pageTree` refers to [Page Tree](/docs/headless/page-tree), it is needed for navigation components, which should be provided by your content source.
### Page

For the `page.tsx`, it may vary depending on your source. You should configure static rendering with `generateStaticParams` and metadata with `generateMetadata`.

Make sure to wrap your content in the [Page](/docs/ui/blocks/page) component, this will also configure typography styles.

<Accordions>
<Accordion title="Example with Fumadocs MDX">

```json doc-gen:file
{
"file": "../../examples/next-mdx/app/docs/[[...slug]]/page.tsx",
"codeblock": {
"meta": "title=\"app/docs/[[...slug]]/page.tsx\""
}
}
```

</Accordion>
</Accordions>

### Search

Use the default document search based on Flexsearch. [Learn to configure Document Search](/docs/headless/search/flexsearch) for your content source.

<Accordions>
<Accordion title="Example with Fumadocs MDX">

```json doc-gen:file
{
"file": "../../examples/next-mdx/app/api/search/route.ts",
"codeblock": {
"meta": "title=\"app/api/search/route.ts\""
}
}
```

</Accordion>
</Accordions>

## Enjoy!

Now, Create your first mdx file in the docs folder.
Now, create your first mdx file in the docs folder.

```mdx title="content/docs/index.mdx"
---
Expand All @@ -176,7 +74,7 @@ title: Hello World

Run the app in development mode and see http://localhost:3000/docs.

```bash
```package-install
npm run dev
```

Expand Down Expand Up @@ -256,14 +154,8 @@ If you find anything confusing, please give your feedback on [Github Discussion]
description="Add themes to Fumadocs UI"
/>
<Card
href="/docs/ui/components/codeblock"
title="Code Block"
description="Learn how to use code blocks in MDX"
href="/docs/ui/manual-installation"
title="Manual Installation"
description="Create fumadocs app from scratch"
/>
</Cards>

## Terminology

For a better understanding of the docs, there are some common terminologies you should know:

**Content Source:** The source of your content, for example, Fumadocs MDX, MDXTS and ContentLayer are examples of content source.
166 changes: 166 additions & 0 deletions apps/docs/content/docs/ui/manual-installation.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
---
title: Manual Installation
description: Create a new fumadocs project from sketch.
icon: Rocket
---

## Getting Started

Create a new Next.js application with `create-next-app`, and install required packages.

```package-install
fumadocs-ui fumadocs-core
```

### Configuration

You can choose a **content source** you prefer.

There is a list of supported sources:

- [Setup Fumadocs MDX](/docs/mdx)
- [Setup Contentlayer](/docs/headless/contentlayer)

You have to configure the library correctly following their setup guide before continuing.

### Root Layout

Wrap the entire application inside [Root Provider](/docs/ui/blocks/root-provider).

```tsx
import { RootProvider } from 'fumadocs-ui/provider';
import type { ReactNode } from 'react';

export default function RootLayout({ children }: { children: ReactNode }) {
return (
<html lang="en">
<body>
<RootProvider>{children}</RootProvider>
</body>
</html>
);
}
```

### Styles

<Tabs items={['Vanilla', 'Tailwind CSS']}>
<Tab value='Vanilla'>

Import the pre-built stylesheet in the root layout.

```ts title="layout.tsx"
import 'fumadocs-ui/style.css';
```

</Tab>
<Tab value='Tailwind CSS'>

Use the official Tailwind CSS plugin.

```json doc-gen:file
{
"file": "./content/docs/example/tailwind.config.js",
"codeblock": {
"meta": "title=\"tailwind.config.js\""
}
}
```

</Tab>

</Tabs>

> It doesn't come with a default font, you may choose one from `next/font`.
### Layout

Create a new catch-all route `/app/docs/[[..slugs]]` for our docs, and give it a proper layout.

```tsx title="app/docs/layout.tsx"
import { DocsLayout } from 'fumadocs-ui/layout';
import { pageTree } from '@/app/source';
import type { ReactNode } from 'react';

export default function RootDocsLayout({ children }: { children: ReactNode }) {
return (
<DocsLayout tree={pageTree} nav={{ title: 'My App' }}>
{children}
</DocsLayout>
);
}
```

> `pageTree` refers to Page Tree, it should be provided by your content source.
### Page

For the `page.tsx`, it may vary depending on your source. You should configure static rendering with `generateStaticParams` and metadata with `generateMetadata`.

Wrap your content in the [Page](/docs/ui/blocks/page) component.

<Tabs id='content-source' items={['Fumadocs MDX', 'Contentlayer']}>
<Tab value='Fumadocs MDX'>

```json doc-gen:file
{
"file": "../../examples/next-mdx/app/docs/[[...slug]]/page.tsx",
"codeblock": {
"meta": "title=\"app/docs/[[...slug]]/page.tsx\""
}
}
```

</Tab>
<Tab value='Contentlayer'>

```json doc-gen:file
{
"file": "../../examples/contentlayer/app/docs/[[...slug]]/page.tsx",
"codeblock": {
"meta": "title=\"app/docs/[[...slug]]/page.tsx\""
}
}
```

</Tab>

</Tabs>

### Search

Use the default document search based on Flexsearch.

<Tabs id='content-source' items={['Fumadocs MDX', 'Contentlayer']}>
<Tab value='Fumadocs MDX'>

```json doc-gen:file
{
"file": "../../examples/next-mdx/app/api/search/route.ts",
"codeblock": {
"meta": "title=\"app/api/search/route.ts\""
}
}
```

</Tab>
<Tab value='Contentlayer'>

```json doc-gen:file
{
"file": "../../examples/contentlayer/app/api/search/route.ts",
"codeblock": {
"meta": "title=\"app/api/search/route.ts\""
}
}
```

</Tab>

</Tabs>

Learn more about [Document Search](/docs/headless/search).

### Done

You can start the dev server and start writing content.
Loading

0 comments on commit 2498124

Please sign in to comment.