# Fumadocs (Framework Mode, Next.js): Build Your Own
URL: /docs/next/integrations/content/custom
Source: https://raw.githubusercontent.com/fuma-nama/fumadocs/refs/heads/main/apps/docs/content/docs/(framework)/[framework]/integrations/content/custom.mdx

Build your own content source for Fumadocs.

## Introduction [#introduction]

There are two ways to implement a custom content source:

### Using Loader API [#using-loader-api]

Loader API has a file-system-like interface for integrating different content sources.

See [Loader API `source`](/docs/headless/source-api/source) for details.

### Using Low-Level API [#using-low-level-api]

For more robust control, you can use lower level APIs directly.

#### Page Tree [step] [#page-tree]

You can either hardcode the page tree, or write some code to generate one.
See [Definitions of Page Tree](/docs/headless/page-tree).

Pass your page tree to `DocsLayout` in your docs layout:

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

export default function Layout({ children }: { children: ReactNode }) {
  return (
    <DocsLayout
      // [!code ++:5]
      tree={
        {
          // your own tree
        }
      }
    >
      {children}
    </DocsLayout>
  );
}
```

The page tree is like a smarter "sidebar items", they will be referenced everywhere in the UI for navigation elements, such as the page footer.

#### Page Content [step] [#page-content]

For docs page, it's the same logic:

- Define path params (`slugs`).
- Fetch page content from path params.
- Render the content (inside the `DocsPage` component).

You may need table of contents, which can be generated on your own, or using the [`getTableOfContents`](/docs/headless/utils/get-toc) utility (Markdown/MDX only).

Render it in the docs route of your framework:

```tsx title="components/docs-page.tsx"
import { DocsPage, DocsBody } from 'fumadocs-ui/layouts/docs/page';
import { getPage } from './my-content-source';

export function Page({ slugs }: { slugs: string[] }) {
  const page = getPage(slugs);
  // respond with 404 using the API of your framework
  if (!page) return null;

  return (
    <DocsPage toc={page.tableOfContents}>
      <DocsBody>{page.render()}</DocsBody>
    </DocsPage>
  );
}
```

#### Pre-rendering [step] [#pre-rendering]

Pre-render pages, especially the frequently visited ones, to improve initial load time.

Define the [`generateStaticParams`](https://nextjs.org/docs/app/api-reference/functions/generate-static-params) function to populate dynamic and catch-all routes.

When pre-rendering pages from a remote source, make sure to optimize repeated reads during the build phase.
For example, if you're fetching content via GitHub API, it is better to clone the repository content locally for pre-rendering.

```text tab="Before"
/docs/* -> GET github.com
/docs/introduction -> GET github.com
/docs/my-page -> GET github.com
Error: API Ratelimit
```

```text tab="After"
start -> git clone
/docs/* -> ls
/docs/introduction -> read file
/docs/my-page -> read file
```

#### Document Search [step] [#document-search]

This can be difficult considering your content may not be necessarily Markdown/MDX.
For Markdown and MDX, the built-in [Search API](/docs/headless/search/orama) + search index usage is adequate for most use cases.
Otherwise, you will have to bring your own implementation.

We recommend 3rd party solutions like Orama or Algolia Search. They are more flexible than the built-in Search API, and is easier to integrate with remote sources.
Fumadocs offers a variant of [Search Integrations](/docs/headless/search).