Content Collections

View as Markdown

Content Collections allow you to manage Markdown or MDX content with strict type safety.

Directory Structure

Collections live in src/content. Each subdirectory is a collection.

src/content/
  blog/                # "blog" collection
    post-1.md
    post-2.mdx
  docs/                # "docs" collection
    guide.md
  config.ts            # Configuration file

Defining Collections

You define your collections in src/content/config.ts.

import { defineCollection, z } from "@neutron-build/core/content";

const blog = defineCollection({
  schema: z.object({
    title: z.string(),
    date: z.date(),
    tags: z.array(z.string()),
    draft: z.boolean().default(false),
  }),
});

export const collections = {
  blog,
};

Editing in the browser

Collections are files in the repository, edited in a code editor. If the site's owner should edit posts, pages and lists from a browser instead, add the optional CMS. It is a separate package and nothing loads it unless a site installs it.