# Fumadocs (Framework Mode, Waku): Notion
URL: /docs/waku/integrations/content/notion
Source: https://raw.githubusercontent.com/fuma-nama/fumadocs/refs/heads/main/apps/docs/content/docs/(framework)/[framework]/integrations/content/notion.mdx

Publish the pages of a Notion database with Fumadocs.

`@fumadocs/notion` loads the pages of a Notion database as a [content source](/docs/headless/source-api), and renders their blocks on the server with Fumadocs UI.

## Setup [#setup]

```package-install
@fumadocs/notion @notionhq/client
```

Add its styles after the Fumadocs UI styles:

```css title="Tailwind CSS"
@import 'fumadocs-ui/css/neutral.css';
@import 'fumadocs-ui/css/preset.css';
/* [!code ++] */
@import '@fumadocs/notion/css/preset.css';
```

### Notion Database [step] [#notion-database]

[Create a Notion integration](https://developers.notion.com/docs/getting-started), and connect it to the database of your pages. Each row of the database is a page, with these properties:

- The title property is the page title.
- `Slug` is the URL path, like `guides/install` for a nested page. Without it, the slug is generated from the title.
- `Description` is the page description.

To use other property names, set the `properties` option of `dynamicSource()`.

Add the integration token and the [data source ID](https://developers.notion.com/guides/get-started/upgrade-guide-2025-09-03) of the database to your environment:

```ini title=".env.local"
NOTION_TOKEN=ntn_...
# not the database ID in the database URL
NOTION_DATA_SOURCE_ID=...
```

### Content Source [step] [#content-source]

Create the source, and get its loader from `getSource()`:

```ts title="lib/source.ts"
import { Client } from '@notionhq/client';
import { dynamicLoader } from 'fumadocs-core/source';
import { createNotion } from '@fumadocs/notion/source';

export const notion = createNotion({
  client: new Client({ auth: process.env.NOTION_TOKEN }),
  dataSourceId: process.env.NOTION_DATA_SOURCE_ID!,
});

const source = dynamicLoader(
  notion.dynamicSource({
    // only publish the rows with `Published` checked
    query: {
      filter: { property: 'Published', checkbox: { equals: true } },
    },
  }),
  { baseUrl: '/docs' },
);

export async function getSource() {
  return source.get();
}
```

### Rendering Pages [step] [#rendering-pages]

`page.data.load()` fetches the blocks of a page. Render them with `NotionRenderer`:

```tsx tab="src/pages/docs/_layout.tsx"
import type { ReactNode } from 'react';
import { DocsLayout } from 'fumadocs-ui/layouts/docs';
import { getSource } from '@/lib/source';

export default async function Layout({ children }: { children: ReactNode }) {
  const source = await getSource();

  return <DocsLayout tree={source.getPageTree()}>{children}</DocsLayout>;
}
```

```tsx tab="src/pages/docs/[...slugs].tsx"
import type { PageProps } from 'waku/router';
import { unstable_notFound } from 'waku/router/server';
import { getSource } from '@/lib/source';
import {
  NotionRenderer,
  blocksToTableOfContents,
  createNotionFileUrlResolver,
} from '@fumadocs/notion';
import { DocsPage, DocsBody, DocsDescription, DocsTitle } from 'fumadocs-ui/layouts/docs/page';

export default async function Page({ slugs }: PageProps<'/docs/[...slugs]'>) {
  const source = await getSource();
  const page = source.getPage(slugs);
  if (!page) unstable_notFound();

  const { blocks } = await page.data.load();

  return (
    <DocsPage toc={blocksToTableOfContents(blocks)}>
      <DocsTitle>{page.data.title}</DocsTitle>
      <DocsDescription>{page.data.description}</DocsDescription>
      <DocsBody>
        <NotionRenderer
          blocks={blocks}
          getFileUrl={createNotionFileUrlResolver({ pageId: page.data.id })}
        />
      </DocsBody>
    </DocsPage>
  );
}

export const getConfig = async () => ({ render: 'dynamic' }) as const;
```

### File Route [step] [#file-route]

Notion-hosted files, like images and PDFs, have URLs that expire after about an hour. `createNotionFileUrlResolver()` points them to a route that redirects to a fresh URL:

```ts title="src/pages/_api/api/notion/file.ts"
import { createNotionFileHandler } from '@fumadocs/notion';
import { notion } from '@/lib/source';

export const GET = createNotionFileHandler(notion);
```

To mount the route at another path, pass the same path to the resolver:

```ts
createNotionFileUrlResolver({ pageId: page.data.id, path: '/notion/file' });
```

## Revalidation [#revalidation]

The loader keeps the pages in memory. Revalidate it after editing Notion, for example from a webhook:

```ts title="lib/source.ts"
export function revalidateNotion() {
  return source.revalidate();
}
```

To fetch the latest content on every request, like for previews, invalidate it before reading:

```ts title="lib/source.ts"
export async function getSource() {
  source.invalidate(); // [!code ++]
  return source.get();
}
```

## Customizing Blocks [#customizing-blocks]

Pass `components` to override the rendering of a block type:

```tsx
<NotionRenderer
  blocks={blocks}
  components={{
    callout({ block, children, renderRichText }) {
      return (
        <aside className="rounded-lg bg-fd-muted p-4">
          {renderRichText(block.callout.rich_text)}
          {children}
        </aside>
      );
    },
  }}
  // Shiki by default, `false` for plain code, or `(code, language) => ReactNode`
  highlightCode={false}
/>
```

## Limitations [#limitations]

- Links to sub-pages and other Notion pages point to Notion, since only the rows of the database are pages on your site.
- The file route needs a server. On a static export, host files outside Notion, and leave out `getFileUrl`.