# Fumadocs Core (the core library of Fumadocs): Source
URL: /docs/headless/source-api/source
Source: https://raw.githubusercontent.com/fuma-nama/fumadocs/refs/heads/main/apps/docs/content/docs/headless/source-api/source.mdx

Setup sources for Loader API

## Overview [#overview]

Content loader accepts different content sources based on a `source` interface.

### Multiple Sources [#multiple-sources]

Pass a record of source objects instead

```ts
import { loader } from 'fumadocs-core/source';
import { blog, docs } from 'collections/server';
import { lucideIconsPlugin } from 'fumadocs-core/source/lucide-icons';

export const source = loader(
  {
    docs: docs.toFumadocsSource(),
    openapi: blog.toFumadocsSource(),
  },
  {
    baseUrl: '/docs',
  },
);
```

To access properties exclusive to each source:

```ts
const page = source.getPage(['...']);

if (page.type === 'docs') {
  console.log(page.data);
} else {
  console.log(page.data);
}
```

### Static Source [#static-source]

To plug your own content source, create a `StaticSource` object.

Since Loader API doesn't rely on file system, file paths only allow virtual paths like `file.mdx` and `content/file.mdx`, `./file.mdx` and `D://content/file.mdx` are not allowed.

```ts twoslash
import type { StaticSource } from 'fumadocs-core/source';

export function createMySource(): StaticSource<{
  metaData: { title: string; pages: string[] }; // Your custom type
  pageData: { title: string; description?: string }; // Your custom type
}> {
  return {
    files: [
      {
        type: 'page',
        path: 'folder/index.mdx',
        data: {
          title: 'Hello World',
          // ...
        },
      },
      {
        type: 'meta',
        path: 'meta.json',
        data: {
          title: 'Docs',
          pages: ['folder'],
          // ...
        },
      },
    ],
  };
}
```

With [i18n](/docs/headless/internationalization/config), the language of a file is parsed from its path, unless the file specifies a `locale`.

### Dynamic Source [#dynamic-source]

For content sources with revalidation, return a `DynamicSource` instead:

```ts
import type { DynamicSource } from 'fumadocs-core/source';

export function createMySource(): DynamicSource<{
  metaData: { title: string; pages: string[] };
  pageData: { title: string; description?: string };
}> {
  return {
    async files() {
      return [
        {
          type: 'page',
          path: 'folder/index.mdx',
          data: {
            title: 'Hello World',
          },
        },
        {
          type: 'meta',
          path: 'meta.json',
          data: {
            title: 'Docs',
            pages: ['folder'],
          },
        },
      ];
    },
    configure(loader) {
      // you can revalidate the loader from source, e.g.
      onMyEvent(() => {
        void loader.revalidate();
      });
    },
  };
}
```

Dynamic sources can only be consumed by [`dynamicLoader()`](/docs/headless/source-api#dynamic-loader).

## Path Params [#path-params]

To support [path params](/docs/headless/page-conventions#path-params) in your source, pass a file like `[framework]/deploy.mdx` as one virtual file. The loader generates a page for each value, with the data from `dataAt()`, or `data` without it. Meta files work the same way:

```ts twoslash
import type { StaticSource } from 'fumadocs-core/source';

const files: StaticSource['files'] = [
  {
    type: 'page',
    path: '[framework]/deploy.mdx',
    data: { title: 'Deploy' },
    dataAt: (params) => ({ title: `Deploy on ${params.framework}` }),
  },
  {
    type: 'meta',
    path: '[framework]/meta.json',
    data: { staticParams: [{ framework: 'waku' }, { framework: 'astro' }] },
    dataAt: (params) => ({ title: params.framework }),
  },
];
```

### Listing Params [#listing-params]

To resolve the data of each value ahead of the loader, like frontmatter in code, `getStaticParams()` lists the params with the same rules. It reads the `staticParams` of meta files from your storage, by their paths without extension:

```ts twoslash
import { getStaticParams, type Params } from 'fumadocs-core/source';

declare const frontmatter: { staticParams?: Params[] };
declare const metaFiles: Map<string, { staticParams?: Params[] }>;
// ---cut---
const params = getStaticParams('[framework]/deploy.mdx', {
  staticParams: frontmatter.staticParams,
  readStaticParams: (path) => metaFiles.get(path)?.staticParams,
});
```

It returns `undefined` when nothing lists the values. The file is then one page at its literal path.

### Custom Props [#custom-props]

To support [custom props](/docs/headless/source-api#custom-props), `dataAt()` takes them as a second argument, with the page data after the loader plugins. Return that data rendered for the params and custom props:

```tsx twoslash
import type { StaticSource } from 'fumadocs-core/source';

declare function pageAt(props: object): { title: string };
// ---cut---
const files: StaticSource['files'] = [
  {
    type: 'page',
    path: '[framework]/deploy.mdx',
    data: pageAt({}),
    dataAt: (params, custom) =>
      custom ? { ...custom.data, ...pageAt({ ...params, ...custom.props }) } : pageAt(params),
  },
];
```

A page without `dataAt()` ignores custom props.

### Runtime Outputs [#runtime-outputs]

If your source compiles MDX, compile each file once and pass the page props to its content. To generate the table of contents, search records and Markdown with the same props:

- set `unstable_runtimeOutputs: true` in the data of the file you compile. On Sätteri, set it in the `data` of the compile options.
- add `rehypeHeading` as your last rehype plugin, to generate [heading IDs](/docs/headless/mdx/headings#headings-with-expressions) from the rendered text.

```ts
import { VFile } from 'vfile';

const file = new VFile({
  path: '[framework]/deploy.mdx',
  value: source,
  data: { unstable_runtimeOutputs: true },
});
```

The plugins then export functions instead of values, like `toc` of [Rehype TOC](/docs/headless/mdx/headings#rehype-toc) and the `_markdown` component of [Remark LLMs](/docs/headless/mdx/remark-llms). Call them with the props of each page:

```tsx twoslash
import type { StaticSource } from 'fumadocs-core/source';
import type { StructuredData } from 'fumadocs-core/mdx-plugins/remark-structure';
import type { TOCItemType } from 'fumadocs-core/toc';
import { renderToMarkdown } from 'fumadocs-core/server';
import type { MDXContent, MDXProps } from 'mdx/types';

declare const compiled: {
  default: MDXContent;
  toc: (props: object) => TOCItemType[];
  _markdown: MDXContent;
};
declare const file: { data: { structuredData: StructuredData } };
// ---cut---
const { default: Content, toc, _markdown: Markdown } = compiled;

function pageAt(props: object) {
  return {
    title: 'Deploy',
    body: (own: MDXProps) => <Content {...props} {...own} />,
    toc: toc(props),
    getMarkdown: () => renderToMarkdown(<Markdown {...props} />),
    structuredData: file.data.structuredData,
  };
}

const files: StaticSource['files'] = [
  {
    type: 'page',
    path: '[framework]/deploy.mdx',
    data: pageAt({}),
    dataAt: (params) => pageAt(params),
  },
];
```

For search, read the records of [Remark Structure](/docs/headless/mdx/structure) from `file.data.structuredData`, not from the export. They include every `<show>` branch, and expressions keep their source text.

The `unstable_` prefix means the API may change. Without the flag, a document with [`<show>`](/docs/next/markdown#show) fails to compile when Rehype TOC, Remark Structure or Remark LLMs runs.