Skip to main content

Frontmatter Suite

Require valid frontmatter on every Markdown and MDX content file with registerFrontmatterSuite.

Summary

  • Recursively scans the configured content directories for .md and .mdx files.
  • Checks that frontmatter is present, closed, and declares every required field.
  • Separates blog posts from docs so each gets its own required-field set.

Why Use This Suite?

  1. Guarantees every page ships with the SEO fields a docs site needs to rank and render.
  2. Catches missing or placeholder frontmatter during the test run, before a broken page reaches the build.
  3. Applies the same required-field standard across every docs project, so metadata never varies from one repository to the next.

Examples

Usage

src/tests/frontmatter.test.ts
ts
import { registerFrontmatterSuite } from '@cbnventures/nova/rules/vitest';
import * as vitest from 'vitest';

registerFrontmatterSuite({
  vitest,
  enable: 'all',
  requiredFields: ['id', 'title', 'description', 'keywords', 'tags'],
});

The requiredFields list has no default, so you must declare which keys every non-blog page needs. Pass placeholderSentinel and placeholderBodyPrefix only if your authoring flow uses placeholder markers.

Configuration

FieldTypeDefaultDescription
requiredFieldsstring[]requiredFrontmatter keys every non-blog page must declare.
requiredBlogFieldsstring[]['title', 'authors', 'tags']Frontmatter keys every blog post must declare.
contentDirsstring[]['docs', 'blog']Directories, relative to rootDir, scanned recursively for content files.
blogDirstring'blog'Which content directory is the blog, selecting the blog required-field set.
indexSlugstring | nullnullExpected id for index pages; null disables the index-to-slug remap.
placeholderSentinelstringdisabledSingle-value marker that fails description, keywords, and tags checks.
placeholderBodyPrefixstringdisabledBody prefix that downgrades a file's issues from failures to warnings.
rootDirstringprocess.cwd()Base directory the contentDirs resolve against.
enable'all' | ToggleKey[]requiredWhich checks run. Use 'all' for every check, or a list to freeze an exact set.

Toggle Keys

Toggle KeyDescription
frontmatter-presentRequires a file to open with a frontmatter block.
frontmatter-closedRequires the frontmatter block to have a closing delimiter.
required-fields-present-docsRequires every key in requiredFields on non-blog pages.
required-fields-present-blogRequires every key in requiredBlogFields on blog posts.
id-matches-filenameRequires the id field to match the file name, honoring indexSlug.
description-not-placeholderRequires description to differ from the placeholder sentinel.
keywords-not-placeholderRequires keywords entries to differ from the placeholder sentinel.
keywords-not-emptyRequires the keywords list to contain at least one entry.
tags-not-placeholderRequires tags entries to differ from the placeholder sentinel.
tags-not-emptyRequires the tags list to contain at least one entry.
placeholder-pages-warn-not-failDowngrades issues on placeholder pages to warnings when a prefix is set.

Troubleshooting

  • A missing content directory throws — The suite skips directories that do not exist. Confirm the path is correct if a configured directory is expected to be present.
  • Placeholder checks never fireplaceholderSentinel is disabled by default. Set it to your marker value to enable the placeholder checks.
  • Index pages fail id-matches-filename — Set indexSlug to the expected id so index files map to your chosen slug.