@tomerlichtash/md-collections
v0.1.0
Published
Directory of markdown → validated typed entries (flat / nested-locale layouts, injected schema)
Readme
@tomerlichtash/md-collections
Directory of markdown → validated typed entries. The Astro-defineCollection
half, framework-free: id from the filename, frontmatter parsed with
gray-matter, validated by an injected schema. Synchronous on purpose — works
inside a unified pipeline.
import { loadCollection } from '@tomerlichtash/md-collections';
const participants = loadCollection({
dir: 'content/participants',
schema: participantSchema, // anything with .parse() — zod satisfies, zod not a dep
});
// → [{ id: 'ada-quill', data: {...}, body: '...', filePath: '...' }, ...]Layouts
flat(default):<dir>/<id>.mdnested-locale:<dir>/<id>/index.<locale>.md— one merged entry per id; a frontmatter field equal across locales stays scalar, a differing one becomesRecord<locale, value>(e.g.name: { en: 'Rio Marsh', fr: 'Rio Marche' })
A file that fails the schema throws — validation failures surface at load
time, not later in the build. Nothing here is entity-specific: use it for
pages, posts, sources, any collection. Feed the output to
@tomerlichtash/md-registry when the collection is people.
