Building a site
Everything CaraCMS knows about a site is in caracms.config.ts. It’s plain data: fields are made with helpers, and components are named by their path from the site’s root.
import { defineSite, list, richText, text } from 'caracms/config';
export default defineSite({ services: 'cloud', collections: { pages: { kind: 'sections', folder: 'content/pages', urlBase: '/', nested: true }, }, blocks: { faq: { label: 'Questions', component: 'src/components/caracms/Faq.astro', fields: { heading: text({ heading: true }), items: list({ question: text(), answer: richText() }, { itemLabel: 'question' }), }, }, }, textStyles: {}, page: 'src/components/caracms/Page.astro',});A mistake in the config stops the dev server and the build with a sentence naming the problem.
A block’s key and a field’s key are stored in the content. Never rename one once content uses it: add a new one instead.
Blocks
A block is a config entry and an Astro component. The component keeps your own markup and classes, and draws each field through a component from the package:
---import Block from 'caracms/components/Block.astro';import Media from 'caracms/components/Media.astro';import RichText from 'caracms/components/RichText.astro';import Text from 'caracms/components/Text.astro';import type { BlockProps } from 'caracms/document';import type { TextMediaData } from './text-media.ts';
type Props = BlockProps<TextMediaData>;const { block, cms } = Astro.props;---
<Block cms={cms} class="section"> <Text cms={cms} field="heading" value={block.heading} class="heading" /> <RichText cms={cms} field="body" value={block.body} class="prose" /> <Media cms={cms} field="media" value={block.media} sizes="(min-width: 1024px) 50vw, 100vw" /></Block>Drawing a field through Text, RichText or Media is what makes it editable on the page. On the public site those components add nothing extra; the editor’s markers only appear in the preview.
Fields
All of these come from caracms/config. Each takes a label and a line of help.
Helper | What it holds |
|---|---|
text() | A line of plain text, or several lines. It can be marked as a heading. |
richText() | Paragraphs, lists, bold, italic and links, with h2 and h3 where you allow them. |
lockup() | A heading typed line by line in one of the site’s text styles. |
select() | One of a fixed set of options. |
toggle() | On or off. |
number() | A number. |
date() | A date. |
link() | Words and an address, or an address alone. |
buttons() | A short row of links, each in one of your button styles. |
media() | An image or a video clip, or only one of the two. |
reference() | One document from a collection. |
list() | A list of one field, or of rows with several fields. |
group() | Several fields kept together. |
Where content lives
Decide this before adding a field. The same kind of content should always be in the same place, so editors know where to look.
Lives in | What | For example |
|---|---|---|
A shared block | Pieces that repeat across pages | The header and its menu, the footer, a call to get in touch |
Site Settings | Setup, and details more than one piece shows | The phone number the footer and the Contact page both show |
A collection | Entries with a page each, or shown in more than one place | Case studies, a journal, a team with bio pages |
A list on the block | Data one block shows, in its own order | An FAQ, a logo strip, the case studies Home features |
Collections
A collection is a folder of documents. A sections collection holds pages built from blocks. A fields collection holds entries with a fixed set of fields.
A collection whose entries have pages gets its addresses from one of three places:
Kind | In the config | An entry’s address |
|---|---|---|
No pages | No urlBase | None. Other pages list the entries. |
A prefix in code | urlBase: '/tags/' | /tags/ and the entry’s slug |
Held by a page | heldBy: 'pages' | The holding page’s address, then the slug. Posts move with the Journal page if it moves. |
One catch-all route serves all of them. A collection needs no route file of its own.
The page component
The page component, named by page in the config, draws every page: the document’s head, the header and footer, and the blocks between them. Rules that span blocks belong here, since a block sees only its own data.
The header and footer are shared blocks that fill a slot, so editors can change them and a page can pick a different one.
Forms
A form is declared in the config: its fields, their labels and its messages. The package draws it, checks each submission, stores it and emails it. Editors change a form’s words and its recipients in Site Settings, and read what’s been sent in Submissions.
Keeping content in step
After changing the config, regenerate the schemas and check the content against it:
npx caracms validate --fixIt writes schemas/ from the config and lays each content file out the way the editor saves it. Only whitespace changes. Commit schemas/ with the config change, and restart the dev server so the editor picks the change up.
Run plain validate before a pull request. It exits with an error when the content doesn’t match the config.
Going further
The caracms-blocks skill in your site’s .claude/skills/ has the rest: every field option, block states, slots, text styles, forms in full, and how scripts such as scroll animation behave in the editor’s preview.
llms.txt · llms-full.txt: this site for AI tools