Skip to content

Frontmatter Schemas

Repotype can validate the YAML frontmatter in markdown files against JSON Schema, ensuring documentation consistency.

repotype.yaml
files:
- id: docs
glob: "docs/**/*.md"
frontmatter:
required:
- title
- description

This ensures every markdown file has title and description in its frontmatter.

For complex validation, use a JSON Schema:

repotype.yaml
files:
- id: blog-posts
glob: "blog/**/*.md"
frontmatter:
required: [title, date, author]
schema: schemas/blog-post.schema.json
schemas/blog-post.schema.json
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"required": ["title", "date", "author"],
"properties": {
"title": {
"type": "string",
"minLength": 5,
"maxLength": 100
},
"date": {
"type": "string",
"format": "date"
},
"author": {
"type": "string"
},
"tags": {
"type": "array",
"items": { "type": "string" },
"minItems": 1
},
"draft": {
"type": "boolean",
"default": false
}
},
"additionalProperties": false
}

Bootstrap a schema from your current content:

Terminal window
npx repotype generate schema docs/ schemas/doc.schema.json --pattern "**/*.md"

This analyzes existing frontmatter and generates a schema that matches.

files:
- id: guides
glob: "docs/guides/**/*.md"
frontmatter:
required: [title, description]
schema: schemas/guide.schema.json
- id: api-docs
glob: "docs/api/**/*.md"
frontmatter:
required: [title, endpoint, method]
schema: schemas/api-doc.schema.json
- id: changelog
glob: "CHANGELOG.md"
frontmatter:
required: [title]
{
"type": "object",
"required": ["title", "date", "author"],
"properties": {
"title": { "type": "string" },
"date": { "type": "string", "format": "date" },
"author": { "type": "string" },
"tags": { "type": "array", "items": { "type": "string" } },
"image": { "type": "string", "format": "uri" },
"draft": { "type": "boolean" }
}
}
{
"type": "object",
"required": ["title", "description"],
"properties": {
"title": { "type": "string" },
"description": { "type": "string", "maxLength": 160 },
"sidebar_position": { "type": "integer", "minimum": 0 },
"sidebar_label": { "type": "string" },
"keywords": { "type": "array", "items": { "type": "string" } }
}
}
{
"type": "object",
"required": ["title", "endpoint", "method"],
"properties": {
"title": { "type": "string" },
"endpoint": { "type": "string", "pattern": "^/" },
"method": { "enum": ["GET", "POST", "PUT", "PATCH", "DELETE"] },
"auth": { "type": "boolean" },
"deprecated": { "type": "boolean" }
}
}
CodeMeaning
missing_frontmatterFile has no frontmatter block
missing_required_frontmatter_fieldRequired field missing
frontmatter_schema_violationFrontmatter doesn’t match schema
invalid_frontmatter_yamlFrontmatter YAML is malformed