# Fumadocs MDX (the built-in content source): Collections
URL: /docs/mdx/collections
Source: https://raw.githubusercontent.com/fuma-nama/fumadocs/refs/heads/main/apps/docs/content/docs/mdx/collections.mdx

Collection of content data for your app

## Define Collections [#define-collections]

Define a collection to parse a certain set of files. The examples on this page define collections in `source.config.ts`, while the [Macro API](/docs/mdx/macro) defines them in `lib/source.ts` with largely the same options.

```ts
import { defineCollections } from 'fumadocs-mdx/config';
import { z } from 'zod';

export const blog = defineCollections({
  type: 'doc',
  dir: './content/blog',
  schema: z.object({
    // schema
  }),
  // other options
});
```

### `type` [#type]

The accepted type of collection.

```ts
import { defineCollections } from 'fumadocs-mdx/config';

// only scan for meta files
export const metaFiles = defineCollections({
  type: 'meta',
  // options
});
```

- `type: meta`

  Accept JSON/YAML files and code modules (`meta.ts` or `meta.js`) with a default export. See [Meta](/docs/next/page-conventions#meta). Available options:

  ### MetaCollection

  | Prop      | Type                                                   | Description |
  | --------- | ------------------------------------------------------ | ----------- |
  | `type`    | `"meta"`                                               |             |
  | `schema?` | `CollectionSchema<Schema, SchemaContext> \| undefined` |             |
  | `dir`     | `string`                                               |             |
  | `files?`  | `string[] \| undefined`                                |             |

- `type: doc`

  Markdown/MDX documents, available options:

  ### DocCollection

  | Prop              | Type                                                                                              | Description                                                                                                                                                                                                                                                                 |
  | ----------------- | ------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
  | `type`            | `"doc"`                                                                                           |                                                                                                                                                                                                                                                                             |
  | `compiler?`       | `"mdx" \| "satteri" \| undefined`                                                                 |                                                                                                                                                                                                                                                                             |
  | `mdxOptions?`     | `ProcessorOptions \| ((environment: BuildEnvironment) => Promise<ProcessorOptions>) \| undefined` | By defining a collection-level MDX options, **the default options & plugins will be removed**.                                                                                                                                                                              |
  | `satteriOptions?` | `SatteriOptionsInput`                                                                             | Sätteri compile options. When omitted, the global `satteriOptions` preset is used.                                                                                                                                                                                          |
  | `dir`             | `string`                                                                                          |                                                                                                                                                                                                                                                                             |
  | `files?`          | `string[] \| undefined`                                                                           |                                                                                                                                                                                                                                                                             |
  | `postprocess?`    | `Partial<PostprocessOptions> \| undefined`                                                        |                                                                                                                                                                                                                                                                             |
  | `async?`          | `boolean \| undefined`                                                                            |                                                                                                                                                                                                                                                                             |
  | `dynamic?`        | `boolean \| undefined`                                                                            |                                                                                                                                                                                                                                                                             |
  | `schema?`         | `CollectionSchema<Schema, SchemaContext> \| undefined`                                            |                                                                                                                                                                                                                                                                             |
  | `lastModified?`   | `boolean \| LastModifiedFn \| undefined`                                                          | Expose the last modified date of each document. - `true`: obtained from Git. Requires `git` to be installed. If you are using Vercel, please set the `VERCEL_DEEP_CLONE` environment variable to `true`. - A function: return the last modified time for a given file path. |

### `schema` [#schema]

The schema to validate file data (frontmatter on `doc` type, content on `meta` type).

```ts
import { defineCollections } from 'fumadocs-mdx/config';
import { z } from 'zod';

export const blog = defineCollections({
  type: 'doc',
  dir: './content/blog',
  schema: z.object({
    name: z.string(),
  }),
});
```

> [Standard Schema](https://standardschema.dev) compatible libraries, including Zod, are supported.

Note that the validation is done at build time, hence the output must be serializable.
You can also pass a function that receives the transform context.

```ts
import { defineCollections } from 'fumadocs-mdx/config';
import { z } from 'zod';

export const blog = defineCollections({
  type: 'doc',
  dir: './content/blog',
  schema: (ctx) => {
    return z.object({
      name: z.string(),
      testPath: z.string().default(
        // absolute path of the file
        ctx.path,
      ),
    });
  },
});
```

### `mdxOptions` [#mdxoptions]

Customize MDX options at the collection level, for collections compiled with unified.

> This API is only available on `doc` type.

```ts title="source.config.ts"
import { defineCollections } from 'fumadocs-mdx/config';

export const blog = defineCollections({
  type: 'doc',
  dir: './content/blog',
  mdxOptions: {
    // mdx options
  },
});
```

By design, this will remove all default settings applied by your global config and Fumadocs MDX.
You have full control over MDX options.

You can use [`applyMdxPreset`](/docs/mdx/mdx) to apply the default MDX preset.

```ts title="source.config.ts"
import { applyMdxPreset, defineCollections } from 'fumadocs-mdx/config';

export const blog = defineCollections({
  type: 'doc',
  dir: './content/blog',
  mdxOptions: applyMdxPreset({
    // extend the preset
  }),
});
```

### `compiler` [#compiler]

> This API is only available on `doc` type.

Compile the collection with [Sätteri](/docs/mdx/mdx#satteri) instead of unified, and pass `satteriOptions` in place of `mdxOptions`.

```ts title="source.config.ts"
import { defineCollections } from 'fumadocs-mdx/config';

export const blog = defineCollections({
  type: 'doc',
  dir: './content/blog',
  compiler: 'satteri',
  // optional, defaults to the global `satteriOptions`
  satteriOptions: {
    // Sätteri options
  },
});
```

Unlike `mdxOptions`, the collection-level `satteriOptions` keeps the default preset unless you pass `preset: 'minimal'`. It replaces the global `satteriOptions` instead of merging with them.

### `postprocess` [#postprocess]

> This API is only available on `doc` type.

You can pass build-time information to runtime using the `postprocess` API.

- #### `includeProcessedMarkdown` [#includeprocessedmarkdown]

  Export the Markdown of documents, generated by [Remark LLMs](/docs/headless/mdx/remark-llms). Pass `true` or its options.

  ```ts tab="docs"
  import { defineDocs } from 'fumadocs-mdx/config';

  export default defineDocs({
    docs: {
      postprocess: {
        // [!code ++]
        includeProcessedMarkdown: true,
      },
    },
  });
  ```

  ```ts tab="doc"
  import { defineCollections } from 'fumadocs-mdx/config';

  export const blog = defineCollections({
    type: 'doc',
    postprocess: {
      // [!code ++]
      includeProcessedMarkdown: true,
    },
  });
  ```

  Read it with `getText('processed')`, e.g. from `loader()`:

  ```ts
  import { source } from '@/lib/source';

  const page = source.getPage('...');
  console.log(await page.data.getText('processed'));
  ```

- #### `valueToExport` [#valuetoexport]

  Some remark plugins store their output in `vfile.data` (compile-time memory) which cannot be accessed from your code.

  You can specify the name of properties to include, they will get converted into ESM exports that you can access when importing the MDX file.

  ```ts tab="docs"
  import { defineDocs } from 'fumadocs-mdx/config';

  export default defineDocs({
    docs: {
      postprocess: {
        // [!code ++]
        valueToExport: ['dataName'],
      },
    },
  });
  ```

  ```ts tab="doc"
  import { defineCollections } from 'fumadocs-mdx/config';

  export const blog = defineCollections({
    type: 'doc',
    postprocess: {
      // [!code ++]
      valueToExport: ['dataName'],
    },
  });
  ```

## Define Docs [#define-docs]

Define a collection for Fumadocs.

```ts
import { defineDocs } from 'fumadocs-mdx/config';

export const docs = defineDocs({
  dir: '/my/content/dir',
  docs: {
    // optional, options of `doc` collection
  },
  meta: {
    // optional, options of `meta` collection
  },
});
```

### `dir` [#dir]

Instead of per collection, you should customize content directory from `defineDocs`:

```ts
import { defineDocs } from 'fumadocs-mdx/config';

export const docs = defineDocs({
  dir: 'content/guides',
});
```

### `schema` [#schema-1]

You can extend the default Zod 4 schema of `docs` and `meta`.

```ts
import { defineDocs } from 'fumadocs-mdx/config';
import { metaSchema, pageSchema } from 'fumadocs-core/source/schema';
import { z } from 'zod';

export const docs = defineDocs({
  docs: {
    schema: pageSchema.extend({
      index: z.boolean().default(false),
    }),
  },
  meta: {
    schema: metaSchema.extend({
      // other props
    }),
  },
});
```