Frontmatter

Change how frontmatter is processed

Frontmatter can be manipulated by passing a FrontmatterProcessor, which makes changes to the frontmatter object.

To get full control over the frontmatter object, including filtering of documents based on it, it is possible to inject a custom FontmatterProcessor.

return docs({
  // other options
  frontmatterProcessor: (/*options*/) => {
    // implementation
  },
});

Returning undefined or false will prevent the file from being bundled.

This can be useful, if you want to optimize and bundle only certain files on demand.

export type FrontmatterProcessor<
  TFrontmatter extends UnknownFrontMatter,
  TOptions extends
    MDXBundlerServiceBaseOptions<TFrontmatter> = MDXBundlerServiceBaseOptions<TFrontmatter>,
> = (
  options: TOptions & {
    frontmatter: Partial<TFrontmatter>;
    file: string;
    path: string;
    fields?: FieldDefinitions<TFrontmatter, TOptions>;
  }
) => boolean;