# CMS

Edit Markdown documents in the Console, keep every draft, and publish to your site or a pull request.

Hosts: Node, Docker, Cloudflare, Vercel.


The CMS is the `vite-hub/cms` package, built on [Content](https://vitehub.dev/docs/content). Add `extends: cms` to `server/content.ts`, and ViteHub stores your [document collections](https://vitehub.dev/docs/content/configure#document-collections). It turns on Workspace, Database, and Blob, adds the Workspace and its history tables, and adds a Database when the app has none. You write no Workspace, Database, or schema code.

```ts [server/content.ts]
import { defineContent } from 'vite-hub/content'
import { documents } from 'vite-hub/content/collections'
import { cms } from 'vite-hub/cms'
import { z } from 'zod'

export const content = defineContent({
  extends: cms,
  collections: {
    posts: documents({ path: 'posts/**/*.md', fields: { title: z.string() } }),
  },
})
```

## Pick a setup

Start with the Blob + Database store. One option changes the store, and the collections stay the same.

| Setup | You add | You get |
| --- | --- | --- |
| [Blob + Database store](https://vitehub.dev/docs/cms/get-started) | `extends: cms` in `server/content.ts` | Drafts, revisions, and published documents in your Blob store and Database. Runs wherever Blob and Database work. Scheduled publishing. No GitHub access. |
| [GitHub store, commits to `main`](https://vitehub.dev/docs/cms/configure#github-store) | `extends: [cms, { repo: 'owner/name' }]`, and `VITEHUB_GITHUB_TOKEN` | Documents are files in your repository. A save is a commit on the `vitehub/content` draft branch. A publish is one commit on `main`. Checkout and Console edits meet in Git. No Blob store. |
| [GitHub store with pull requests](https://vitehub.dev/docs/cms/configure#pull-request-mode) | `publish: 'pr'` in the same options | A publish opens a pull request into `main`. Review it, wait for checks, and merge it any way. The Console shows the link until it merges. |

### [One line selects the preset](https://vitehub.dev/docs/cms/get-started)

Add `extends: cms` to `server/content.ts`. `vitehub()` needs no settings for it.

### [No wiring to write](https://vitehub.dev/docs/cms/configure#what-the-preset-adds)

The preset adds the Workspace, its history tables, and a Database if needed. `vitehub inspect definitions` lists each part.

### [Keep content in Git](https://vitehub.dev/docs/cms/configure#github-store)

Set `repo`. Published documents and drafts live on separate branches. A publish is a commit.

### [Publish through pull requests](https://vitehub.dev/docs/cms/configure#pull-request-mode)

`publish: 'pr'` opens a pull request for each publish. Documents stay pending until it merges.

### [Decide who edits and publishes](https://vitehub.dev/docs/cms/access)

Set `access: 'roles'` and give each user a role: `viewer`, `commenter`, `editor`, or `publisher`. Or write your own `authorize`.

### [Edit in the Console](https://vitehub.dev/docs/content/console)

Editors open `/_vitehub/content`, edit fields and body, compare versions, and publish what they reviewed.

## Edit, preview, and publish

The CMS stores the collections. [Content](https://vitehub.dev/docs/content) does the rest, on both stores:

- [Edit in the Console](https://vitehub.dev/docs/content/console): the editor, the media library, and history.
- [Preview drafts](https://vitehub.dev/docs/content/preview) on your own pages before you publish.
- [Edit together](https://vitehub.dev/docs/content/editing-together): presence, edit leases, and live editing.
- [Publish on a schedule](https://vitehub.dev/docs/content/scheduling), on the Blob + Database store.
- [Edit from the terminal](https://vitehub.dev/docs/content/cli) with `vitehub content`. Let an Agent draft and publish with the [Content Agent Capability](https://vitehub.dev/docs/content/agent-capability).
- [Read published documents](https://vitehub.dev/docs/content/server-api) from routes, and from the browser through `/api/content/**`.

## Deploy and operate

- [Roles and access](https://vitehub.dev/docs/cms/access): give each user a role with the Better Auth `admin` plugin.
- [Hosts](https://vitehub.dev/docs/cms/hosts): where each store runs and what to provision before a hosted deploy.
- [Limits and errors](https://vitehub.dev/docs/cms/limits-and-errors): GitHub store limits and the fix for each error code.
- [Server API](https://vitehub.dev/docs/cms/server-api): the imports and every preset option.

<!-- vitehub-docs:section-links -->
## In this section

- [Overview](https://vitehub.dev/raw/docs/cms.md) (this page)
- [Get started](https://vitehub.dev/raw/docs/cms/get-started.md)
- [Configure](https://vitehub.dev/raw/docs/cms/configure.md)
- [Server API](https://vitehub.dev/raw/docs/cms/server-api.md)
- [Hosts](https://vitehub.dev/raw/docs/cms/hosts.md)
- [Limits and errors](https://vitehub.dev/raw/docs/cms/limits-and-errors.md)
- [Roles and access](https://vitehub.dev/raw/docs/cms/access.md)

Next: [Get started](https://vitehub.dev/raw/docs/cms/get-started.md)

All pages: [llms.txt](https://vitehub.dev/llms.txt)
