---
title: "Content Collections Adapter"
description: "The Content Collections Adapter (@fumadocs/content-collections) bridges Content Collections data layers with Fumadocs by supplying factory functions and transformation pipelines that translate cont..."
last_updated: "2026-10-12T07:53:59.831064+00:00"
canonical_url: "https://www.doc0.dev/docs/e8872a72-1909-479c-b585-dc74c6e26726/technical/content-sources/content-collections-adapter"
---

<details>
<summary>Relevant source files</summary>

The following files were used as context for generating this wiki page:

- [packages/content/src/index.ts](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/content/src/index.ts)
- [packages/mdx/src/runtime/server.ts](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/mdx/src/runtime/server.ts)
- [packages/content/src/runtime.ts](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/content/src/runtime.ts)
- [packages/mdx/src/runtime/dynamic.ts](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/mdx/src/runtime/dynamic.ts)
- [packages/content-collections/src/index.ts](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/content-collections/src/index.ts)
- [packages/core/src/source/loader.ts](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/core/src/source/loader.ts)
- [packages/content-collections/src/types.ts](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/content-collections/src/types.ts)
- [packages/mdx/src/plugins/index-file.ts](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/mdx/src/plugins/index-file.ts)
- [packages/local-md/src/index.ts](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/local-md/src/index.ts)
- [packages/asyncapi/src/server/index.tsx](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/asyncapi/src/server/index.tsx)
- [packages/content-collections/package.json](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/content-collections/package.json)
- [packages/content-collections/src/configuration.ts](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/content-collections/src/configuration.ts)
- [packages/preview/src/lib/source/storage.ts](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/preview/src/lib/source/storage.ts)
- [packages/core/src/source/storage/content.ts](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/core/src/source/storage/content.ts)
- [packages/sanity/src/index.ts](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/sanity/src/index.ts)
- [packages/content-collections/tsdown.config.ts](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/content-collections/tsdown.config.ts)
- [packages/core/src/source/client/index.tsx](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/core/src/source/client/index.tsx)
- [packages/openapi/src/ui/base.tsx](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/openapi/src/ui/base.tsx)
- [packages/preview/src/pages/...slugs.tsx](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/preview/src/pages/%5B...slugs%5D.tsx)
- [packages/create-app/template/+orama-cloud/@app/lib/export-static-indexes.ts](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/create-app/template/%2Borama-cloud/%40app/lib/export-static-indexes.ts)
- [packages/local-md/src/storage.ts](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/local-md/src/storage.ts)
- [packages/mdx/src/runtime/types.ts](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/mdx/src/runtime/types.ts)
- [packages/mdx/src/runtime/browser.tsx](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/mdx/src/runtime/browser.tsx)
- [packages/core/src/search/client/orama-cloud-legacy.ts](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/core/src/search/client/orama-cloud-legacy.ts)
- [packages/core/src/search/orama-cloud-legacy.ts](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/core/src/search/orama-cloud-legacy.ts)
- [packages/mdx/src/config/define.ts](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/mdx/src/config/define.ts)
- [packages/mdx/src/loaders/meta.ts](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/mdx/src/loaders/meta.ts)
- [packages/core/src/source/llms.ts](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/core/src/source/llms.ts)
- [packages/preview/src/lib/source/index.ts](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/preview/src/lib/source/index.ts)
- [packages/core/src/search/orama-cloud.ts](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/core/src/search/orama-cloud.ts)
</details>

## Overview

The Content Collections Adapter (`@fumadocs/content-collections`) bridges Content Collections data layers with Fumadocs by supplying factory functions and transformation pipelines that translate content entries into compatible virtual files and sources.

Sources: [packages/content-collections/package.json:2-4](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/content-collections/package.json#L2-L4), [packages/content-collections/src/index.ts:4-10](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/content-collections/src/index.ts#L4-L10)

By normalizing schemas, unifying metadata extensions, and configuring remark/rehype pipelines such as heading generation and code block formatting, the package enables type-safe content management and rendering across Fumadocs applications.

Sources: [packages/content-collections/src/types.ts:4-9](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/content-collections/src/types.ts#L4-L9), [packages/content-collections/src/configuration.ts:58-71](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/content-collections/src/configuration.ts#L58-L71)

## Package architecture and integration entry

### Public Exports and Bundle Configuration

The `@fumadocs/content-collections` package (`@fumadocs/content-collections`) is structured as an ESM-only module targeting Node 22, configured via `tsdown` with TypeScript declaration generation enabled (`dts: true`) and fixed file extensions disabled. The package exposes two public entry points mapped in package exports: the root entry `.` resolving to `./dist/index.js` (with type definitions at `./dist/index.d.ts`) and `./configuration` resolving to `./dist/configuration.js` (with type definitions at `./dist/configuration.d.ts`).

```typescript
import { defineConfig } from 'tsdown';

export default defineConfig({
  dts: true,
  fixedExtension: false,
  target: 'node22',
  format: 'esm',
  entry: ['src/{index,configuration}.ts'],
  deps: {
    onlyBundle: [],
  },
});
```
Sources: [packages/content-collections/tsdown.config.ts:1-12](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/content-collections/tsdown.config.ts#L1-L12)

```json
"type": "module",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
  ".": {
    "types": "./dist/index.d.ts",
    "import": "./dist/index.js"
  },
  "./configuration": {
    "types": "./dist/configuration.d.ts",
    "import": "./dist/configuration.js"
  }
},
```
Sources: [packages/content-collections/package.json:17-29](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/content-collections/package.json#L17-L29)

### Package Dependencies and Peer Requirements

Package execution relies on runtime dependencies for unified document processing and schema validation, alongside peer dependencies that couple the adapter directly with Content Collections core packages and Fumadocs core.

| Dependency Name | Type | Version / Range | Purpose |
| :--- | :--- | :--- | :--- |
| `unified` | dependencies | `^11.0.5` | AST processing and plugin pipeline integration |
| `zod` | dependencies | `^4.4.3` | Schema definition and type validation |
| `@content-collections/core` | devDependencies / peerDependencies | `0.15.1` / `0.x.x` | Core collection management and document building |
| `@content-collections/mdx` | devDependencies / peerDependencies | `^0.2.2` / `0.x.x` | MDX compilation bindings for Content Collections |
| `fumadocs-core` | devDependencies / peerDependencies | `workspace:*` / `15.x.x \|\| 16.x.x` | Virtual file types and source abstractions |
| `@types/node` | devDependencies | `25.9.2` | Node.js type definitions |
| `tsconfig` | devDependencies | `workspace:*` | Shared TypeScript configuration |
| `tsdown` | devDependencies | `0.22.2` | Bundle compilation and build tool |

> [!NOTE]
> The peer dependency range for `fumadocs-core` explicitly requires major version `15.x.x` or `16.x.x`, ensuring interface compatibility with Fumadocs [source loader](https://www.doc0.dev/docs/e8872a72-1909-479c-b585-dc74c6e26726/technical/core-architecture/source-loader) definitions.

Sources: [packages/content-collections/package.json:40-56](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/content-collections/package.json#L40-L56)

## Data contract and schema inheritance

### Interface Definitions

The data contract between Content Collections and Fumadocs relies on two core TypeScript interfaces: `BaseMetaData` and `BaseDocsData`. These interfaces extend Fumadocs core metadata and page data types by injecting the `_meta` property defined by `@content-collections/core`.

```typescript
export interface BaseMetaData extends MetaData {
  _meta: Meta;
}

export interface BaseDocsData extends PageData {
  _meta: Meta;
}
```
Sources: [packages/content-collections/src/types.ts:4-10](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/content-collections/src/types.ts#L4-L10)

| Interface Name | Extending Type | Additional Property | Target Source Mapping |
| :--- | :--- | :--- | :--- |
| `BaseMetaData` | `MetaData` | `_meta: Meta` | `VirtualFile<{ metaData: Meta; pageData: Docs }>` |
| `BaseDocsData` | `PageData` | `_meta: Meta` | `VirtualFile<{ metaData: Meta; pageData: Docs }>` |

> [!IMPORTANT]
> Both `BaseMetaData` and `BaseDocsData` require the presence of `_meta` containing Content Collections core metadata (`Meta`), which supplies file path tracking (`_meta.filePath`) utilized when generating virtual file entries.

Sources: [packages/content-collections/src/index.ts:23-31](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/content-collections/src/index.ts#L23-L31), [packages/content-collections/src/types.ts:4-10](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/content-collections/src/types.ts#L4-L10)

### Type Parameter Constraints

The `createMDXSource` factory function enforces schema inheritance through generic type constraints bounded by `BaseDocsData` and `BaseMetaData`. Documents (`allDocs`) and metadata files (`allMetas`) must conform to these extended data models to produce a typed `Source` containing `metaData` and `pageData`.

```typescript
export function createMDXSource<Docs extends BaseDocsData, Meta extends BaseMetaData>(
  allDocs: Docs[],
  allMetas: Meta[],
): Source<{
  metaData: Meta;
  pageData: Docs;
}> {
```
Sources: [packages/content-collections/src/index.ts:4-10](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/content-collections/src/index.ts#L4-L10)

## Plugin configuration and remark pipelines

### Transform Options and Default Processors

The `transformMDX` function processes documents by invoking `baseCompileMDX` from `@content-collections/mdx` while applying a customized pipeline of remark and rehype plugins [[packages/content-collections/src/configuration.ts:58-97](https://github.com/blade47/blade47/blob/HEAD/packages/content-collections/src/configuration.ts#L58-L97)]. The transformation accepts `TransformOptions`, which inherit from core MDX options while omitting raw plugin arrays in favor of customizable `ResolvePlugins` inputs for both `remarkPlugins` and `rehypePlugins` [packages/content-collections/src/configuration.ts:13-15](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/content-collections/src/configuration.ts#L13-L15). 

```typescript
export interface TransformOptions extends Omit<MDXOptions, 'remarkPlugins' | 'rehypePlugins'> {
  remarkPlugins?: ResolvePlugins;
  rehypePlugins?: ResolvePlugins;

  /**
   * Generate `structuredData`
   *
   * @defaultValue true
   * @deprecated use `remarkStructureOptions` instead
   */
  generateStructuredData?: boolean;

  remarkStructureOptions?: Plugins.StructureOptions | boolean;
  remarkHeadingOptions?: Plugins.RemarkHeadingOptions | boolean;
  rehypeCodeOptions?: Plugins.RehypeCodeOptions | boolean;
  remarkImageOptions?: Plugins.RemarkImageOptions | boolean;
  remarkCodeTabOptions?: Plugins.RemarkCodeTabOptions | boolean;
}
```
Sources: [packages/content-collections/src/configuration.ts:13-30](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/content-collections/src/configuration.ts#L13-L30)

| Option Name | Type | Default Value | Purpose |
| :--- | :--- | :--- | :--- |
| `remarkStructureOptions` | `Plugins.StructureOptions \| boolean` | `generateStructuredData ?? true` | Configures document structure extraction for search indexes |
| `rehypeCodeOptions` | `Plugins.RehypeCodeOptions \| boolean` | `true` | Enables code block [syntax highlighting](https://www.doc0.dev/docs/e8872a72-1909-479c-b585-dc74c6e26726/technical/core-architecture/syntax-highlighting) and processing |
| `remarkHeadingOptions` | `Plugins.RemarkHeadingOptions \| boolean` | `true` | Extracts headings to construct [table of contents](https://www.doc0.dev/docs/e8872a72-1909-479c-b585-dc74c6e26726/technical/ui-layouts/table-of-contents) data |
| `remarkImageOptions` | `Plugins.RemarkImageOptions \| boolean` | `true` | Processes Markdown images (configured with `useImport: false`) |
| `remarkCodeTabOptions` | `Plugins.RemarkCodeTabOptions \| boolean` | `true` | Parses code tab syntax extensions if present in plugins |
| `generateStructuredData` | `boolean` | `undefined` | Legacy flag for `structuredData`; maps to `remarkStructureOptions` |

> [!NOTE]
> The `remarkImageOptions` plugin is hardcoded to set `useImport: false`, ensuring images are parsed inline rather than transformed into ES module imports during compilation.

Sources: [packages/content-collections/src/configuration.ts:72-80](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/content-collections/src/configuration.ts#L72-L80), [packages/content-collections/src/configuration.ts:108-110](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/content-collections/src/configuration.ts#L108-L110)

### Resolution Pipeline and File Data Extraction

Plugins are resolved using `resolvePlugins` and `resolvePlugin`, merging user-provided options with Fumadocs defaults [packages/content-collections/src/configuration.ts:100-122](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/content-collections/src/configuration.ts#L100-L122). A final custom visitor function is appended to the remark pipeline to capture runtime `file.data` properties generated by plugins like table of contents extraction and structured data processing [packages/content-collections/src/configuration.ts:114-120](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/content-collections/src/configuration.ts#L114-L120).

```typescript
    rehypePlugins: resolvePlugins(
      (plugins) => [resolvePlugin(Plugins.rehypeCode, rehypeCodeOptions), ...plugins],
      rest.rehypePlugins,
    ),
    remarkPlugins: resolvePlugins(
      (plugins) => [
        Plugins.remarkGfm,
        resolvePlugin(Plugins.remarkHeading, remarkHeadingOptions),
        resolvePlugin(Plugins.remarkImage, remarkImageOptions, {
          useImport: false,
        }),
        'remarkCodeTab' in Plugins &&
          resolvePlugin(Plugins.remarkCodeTab, remarkCodeTabOptions),
        ...plugins,
        resolvePlugin(Plugins.remarkStructure, remarkStructureOptions),
        () => {
          return (_, file) => {
            data = file.data;
          };
        },
      ],
      rest.remarkPlugins,
    ),
  },
);
```
Sources: [packages/content-collections/src/configuration.ts:100-124](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/content-collections/src/configuration.ts#L100-L124)

> [!CAUTION]
> The nested caching mechanism inside `baseCompileMDX` is explicitly overridden (`cache: async (input, fn) => fn(input)`) to prevent recursive caching conflicts between Content Collections and the MDX compiler [packages/content-collections/src/configuration.ts:90-95](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/content-collections/src/configuration.ts#L90-L95).

Sources: [packages/content-collections/src/configuration.ts:90-95](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/content-collections/src/configuration.ts#L90-L95)

## Virtual file mapping and sources

### Creating MDX Sources

The `createMDXSource` function bridges raw Content Collections arrays into a structured Fumadocs source object [packages/content-collections/src/index.ts:4-10](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/content-collections/src/index.ts#L4-L10). It accepts `allDocs` and `allMetas` collections conforming to `BaseDocsData` and `BaseMetaData` respectively, returning a unified `Source` object containing typed `metaData` and `pageData` generics [packages/content-collections/src/index.ts:4-10](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/content-collections/src/index.ts#L4-L10).

```typescript
export function createMDXSource<Docs extends BaseDocsData, Meta extends BaseMetaData>(
  allDocs: Docs[],
  allMetas: Meta[],
): Source<{
  metaData: Meta;
  pageData: Docs;
}> {
```
Sources: [packages/content-collections/src/index.ts:4-10](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/content-collections/src/index.ts#L4-L10)]

```typescript
type File = VirtualFile<{
  metaData: Meta;
  pageData: Docs;
}>;

```
Sources: [packages/content-collections/src/index.ts:11-15](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/content-collections/src/index.ts#L11-L15)]

### File Mapping Structure

The returned source maps each document and metadata record into a typed `VirtualFile` array [packages/content-collections/src/index.ts:16-35](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/content-collections/src/index.ts#L16-L35). Document entries are mapped with a `'page'` type, retaining their original data and path derived from `v._meta.filePath` [packages/content-collections/src/index.ts:18-25](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/content-collections/src/index.ts#L18-L25). Metadata entries are mapped with a `'meta'` type using the same path extraction strategy [packages/content-collections/src/index.ts:26-33](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/content-collections/src/index.ts#L26-L33).

```typescript
return {
  files: [
    ...allDocs.map(
      (v) =>
        ({
          type: 'page',
          data: v,
          path: v._meta.filePath,
        }) satisfies File,
    ),
    ...allMetas.map(
      (v) =>
        ({
          type: 'meta',
          data: v,
          path: v._meta.filePath,
        }) satisfies File,
    ),
  ],
};
```
Sources: [packages/content-collections/src/index.ts:16-35](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/content-collections/src/index.ts#L16-L35)]

| Virtual File Property | Mapping Source | Type Definition | Purpose |
| :--- | :--- | :--- | :--- |
| `type` | Literal string `'page'` / `'meta'` | `'page'` \| `'meta'` | Discriminates document content from folder metadata files |
| `data` | `v` (from `allDocs` or `allMetas`) | `Docs` \| `Meta` | Holds the validated collection record payload |
| `path` | `v._meta.filePath` | `string` | Defines the virtual file path used for routing and tree building |

Sources: [packages/content-collections/src/index.ts:18-33](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/content-collections/src/index.ts#L18-L33), [packages/content-collections/src/types.ts:4-10](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/content-collections/src/types.ts#L4-L10)

> [!NOTE]
> The TypeScript `satisfies` operator is used during array mapping to ensure every virtual file strictly adheres to the local `File` type without widening inferred literal types [packages/content-collections/src/index.ts:24](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/content-collections/src/index.ts#L24), [packages/content-collections/src/index.ts:32](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/content-collections/src/index.ts#L32).

Sources: [packages/content-collections/src/index.ts:24](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/content-collections/src/index.ts#L24), [packages/content-collections/src/index.ts:32](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/content-collections/src/index.ts#L32)

## Collection definition and schema spec

### Collection Definition Primitives

Fumadocs provides content definition helpers such as `defineDocs`, `defineCollections`, and `docsCollection` to structure documentation workspaces. The `defineDocs` helper accepts a target directory and configuration overrides for documentation and metadata collections, defaulting to `content/docs` when no directory is specified [packages/mdx/src/config/define.ts:112-144](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/mdx/src/config/define.ts#L112-L144). 

```typescript
export function defineDocs<
  DocSchema extends StandardSchemaV1 = typeof pageSchema,
  MetaSchema extends StandardSchemaV1 = typeof metaSchema,
>(options: {
  dir?: string;
  docs?: Omit<DocCollection<DocSchema>, 'dir' | 'type'>;
  meta?: Omit<MetaCollection<MetaSchema>, 'dir' | 'type'>;
}): DocsCollection<DocSchema, MetaSchema> {
  const dir = options.dir ?? 'content/docs';

  return {
    type: 'docs',
    dir,
    docs: defineCollections({
      type: 'doc',
      dir,
      schema: pageSchema as any,
      ...options?.docs,
    }),
    meta: defineCollections({
      type: 'meta',
      dir,
      schema: metaSchema as any,
      ...options?.meta,
    }),
  };
}
```
Sources: [packages/mdx/src/config/define.ts:112-144](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/mdx/src/config/define.ts#L112-L144)]

### Standard Schema Validation Specifications

Collections enforce runtime data integrity using the Standard Schema specification (`StandardSchemaV1`), supporting static schemas or context-aware schema generator functions [packages/content/src/index.ts:1-14](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/content/src/index.ts#L1-L14), [packages/mdx/src/config/define.ts:9-12](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/mdx/src/config/define.ts#L9-L12). The `docsCollection` factory constructs combined MDX document collections and JSON/YAML metadata collections backed by `pageSchema` and `metaSchema` defaults [packages/content/src/index.ts:35-53](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/content/src/index.ts#L35-L53).

| Collection Property | Type / Signature | Default Value | Purpose |
| :--- | :--- | :--- | :--- |
| `dir` | `string` | `'content/docs'` | Root filesystem directory scanned for collection files |
| `docs` | `DocsMDXCollectionConfig` | `pageSchema` | Configuration and validation schema for MDX page frontmatter |
| `meta` | `DataCollectionConfig` | `metaSchema` | Configuration and validation schema for folder metadata files |
| `schema` | `Schema \| ((ctx) => Schema)` | `pageSchema` / `metaSchema` | Standard Schema validator or dynamic factory function |

Sources: [packages/content/src/index.ts:35-53](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/content/src/index.ts#L35-L53), [packages/mdx/src/config/define.ts:9-12](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/mdx/src/config/define.ts#L9-L12), [packages/mdx/src/config/define.ts:112-144](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/mdx/src/config/define.ts#L112-L144)]

> [!IMPORTANT]
> When defining a collection schema using a function, the context parameter provides file-specific metadata `{ path: string; source: string }`, allowing validation rules to adapt dynamically based on file location or content structure.

Sources: [packages/mdx/src/config/define.ts:9-12](https://github.com/blade47/fumadocs/blob/a9f988897e7dc4ef3d62b2865d80da2f5607701e/packages/mdx/src/config/define.ts#L9-L12)]

## Related

- [Source Loader](https://www.doc0.dev/docs/e8872a72-1909-479c-b585-dc74c6e26726/technical/core-architecture/source-loader)


## Sitemap

See the full [sitemap](https://www.doc0.dev/docs/e8872a72-1909-479c-b585-dc74c6e26726/llms.txt) for all pages in this wiki.
