Frontmatter transformers
Custom frontmatter is first-class in Leadtype. Define a schema when your docs need product-specific fields, then use transformers to derive or normalize those fields as the pipeline runs.
Transformer hook types live under leadtype/transformers when you want explicit annotations in shared config helpers.
Use transformers for release-channel behavior such as canary, RC, preview, or
stable builds. Those channels describe the build or deployment, not the page
source, so they should be derived from config, environment, package version, or
git ref instead of authored into page status.
Typed source data
Pass the same schema and transformers to lower-level APIs when you are not using leadtype generate:
Without a schema, frontmatter remains Record<string, unknown>. With a schema, page and transformer payloads are typed from the schema output.
Hook order
Transformers run in array order. A hook may return a replacement object or return nothing to keep the current value.
| Hook | Purpose |
|---|---|
beforeParse | Edit raw source before frontmatter and MDX parsing. |
afterFrontmatter | Add, validate, or normalize frontmatter-derived metadata. |
afterMdxAst | Adjust the transformed mdast before markdown serialization. |
afterFlattenMarkdown | Customize flattened markdown before it is written or indexed. |
beforeSearchIndex | Edit the full search document list. |
beforeSearchChunk | Edit individual search chunks. |
beforeLlmsTxt | Customize root or docs-scoped llms.txt. |
beforeLlmsFull | Customize llms-full.txt. |
beforeAgentsMd | Customize package-bundled AGENTS.md. |
Hook errors include the transformer name, hook name, and source path when Leadtype has one.
beforeSearchChunk receives the current chunk text and metadata. If you change text, Leadtype recalculates the chunk length before indexing, so you do not need to update length manually.