Overview / 03
Content Model
Zole parses files inside each collection directory into typed metadata (meta), preserved body content (body), and generated relation helpers.
Filenames and locales
The parser extracts slug and optional locale directly from the filename:
| Mode | Filename pattern | Example |
|---|---|---|
Standard (i18n: false) |
{slug}.{ext} |
quickstart.md, faq.mdx |
Localized (i18n: true) |
{slug}.{locale}.{ext} |
quickstart.en.md, quickstart.zh-CN.md |
Custom regex patterns can be supplied via collection config.slugPattern with 2 positional groups (slug, ext) or 3 positional groups (slug, locale, ext).
Markdown, MDX, and JSON formats
- Markdown (
.md): YAML frontmatter delimited by---(supporting inline values, dash lists, indented maps, and multiline JSON-style blocks) plus Markdown body. - MDX (
.mdx): Auto-detects YAML frontmatter or ESMexport const meta = { ... }alongside JSX/MDX body content. - JSON (
.json): Object files validated directly against the collection Zod schema.
When zole update or writer modifies frontmatter in .md / .mdx files, untouched keys, comments, and formatting stay intact while target keys update cleanly.
Relations and computed fields
Declare cross-collection references in defineCollection so zole lint catches dangling references at build time:
import { defineCollection } from "@zolekit/core";
import { z } from "zod";
export const { meta, relations } = defineCollection({
schema: z.object({
title: z.string(),
author: z.string(),
related: z.array(z.string()).default([]),
}),
relations: {
author: "authors",
related: "articles",
},
computed: {
wordCount: (item) => (item.body ? item.body.trim().split(/\s+/).length : 0),
},
});
Multi-type collections
Collections that mix multiple document shapes in one directory can dispatch schemas by filename regex using defineMultiTypeCollection.