Validation

Validate your files via Zod

Usage

The file validation is based on Zod. When an invalid file is detected, it will throw an error immediately.

To customise the schemas, you have to install zod.

npm install zod

Now you can override or extend the default zod schemas by passing the schema option.

Example

Extend the default frontmatter schema:

source.ts
import { defaultSchemas, fromMap } from 'next-docs-mdx/map';
import { z } from 'zod';
 
const frontmatterSchema = defaultSchemas.frontmatter.extend({
  preview: z.string().optional(),
});
 
const utils = fromMap(map, {
  schema: {
    frontmatter: frontmatterSchema,
  },
});

Typescript

Thanks to the Typescript magic, your custom Zod schema type should be automatically inferred.

source.ts
utils.pages; // should be your own frontmatter

Last updated on