# Edit Content in the Console

The Console's Content section at `/_vitehub/content` edits the [collections](https://vitehub.dev/docs/content/configure#document-collections) of `server/content.ts`. Your public site needs no edit button or overlay.

The section appears when `defineContent()` has `collections`, not with only read-only Sources. Discovery reads the file without running it. If it cannot follow the collections, such as an object imported from another file, it keeps the section and lists what the runtime defines. It shows every collection the signed-in user may read.

## Find your way around

`/_vitehub/content` opens the dashboard:

- Counts of draft, changed, published, and deleted documents in the collections you may read.
- **Needs publishing** lists each unpublished change, newest first. **Publish** in the header publishes all of them, exactly as shown. Writers see the list without the button.
- **Scheduled** lists [scheduled publishes](https://vitehub.dev/docs/content/scheduling), soonest first, if any.
- **Recent activity** shows who saved, deleted, restored, or published which document, and when. It shows the latest eight. **Show all** shows the rest.
- **Collections** lists each collection with its draft, changed, and published counts, and **New** when you may edit it. A last **Settings** row counts the singletons and opens the Settings page.

The sidebar lists the dashboard, each collection with its draft and changed counts, and **Settings** and **Media** under **Manage**. **Settings** appears when you define a [singleton](https://vitehub.dev/docs/content/configure#singletons-and-data-files), and lists each one with its state. Singletons are not listed with the collections. Lists name a singleton by its `label`, not its file name. **Media** appears when Blob is on and opens the [media library](https://vitehub.dev/docs/content/console#media-library). Each page has a URL, such as `/_vitehub/content/-/media`. See [Section pages and URLs](https://vitehub.dev/docs/development/console#section-pages-and-urls).

When the app lacks something a feature needs, the Console shows the fix in its place:

- Without [`authorize`](https://vitehub.dev/docs/content/configure#access) in `defineContent()`, nobody can read documents. The sidebar and dashboard ask you to add it.
- Without a Schedule Definition that calls [`content.publishDue()`](https://vitehub.dev/docs/content/scheduling#run-due-schedules), **Schedule…** is off, and an **Overdue** schedule shows the fix.
- When Console data needs a signed-in user, such as with `console: { auth: 'app' }`, it asks you to sign in.

<kbd>⌘</kbd> <kbd>K</kbd> searches all drafts by title, id, fields, and body. <kbd>Enter</kbd> opens a document. <kbd>⌘</kbd> <kbd>Enter</kbd> opens it in a new tab. Search also creates documents and reviews and publishes all changes. See [Search](https://vitehub.dev/docs/development/console#search).

## What editors can do

| Task | How |
| --- | --- |
| Find a document | Search, filter by state (draft, changed, published, deleted) or by enum, boolean, and tag fields, and sort by title or the first date field. **Updated** shows the last change. Hover it for the exact time. |
| Edit fields | Property rows under the title, from the collection's [JSON Schema](https://vitehub.dev/docs/content/configure#fields). Empty optional fields fold behind **Show N more**. JSON and YAML documents have no body, so their rows fill the page and show every field. |
| Edit the body | A block editor over the Markdown. Select text to format it. Type <kbd>/</kbd> to insert blocks, images, and the collection's [components](https://vitehub.dev/docs/content/configure#define-collections). Hover a block for ⋮⋮ (move, turn into, duplicate, copy link, delete) and + (insert below). |
| Edit SEO | A [`seo()` field](https://vitehub.dev/docs/content/seo#seo-fields) adds an **SEO** group with counters, fallbacks, previews, and **Hide from search**. See [SEO](https://vitehub.dev/docs/content/seo#console). |
| Edit settings | Open **Settings**, or find the singleton with <kbd>⌘</kbd> <kbd>K</kbd>. It opens straight into its editor with field defaults until the first edit saves it. The Console cannot delete it. |
| See the file | **Source** (<kbd>⌘</kbd> <kbd>/</kbd>) shows the stored file, with read-only frontmatter and an editable body. |
| Save | Drafts save one second after typing stops. <kbd>⌘</kbd> <kbd>S</kbd> saves at once. A new document saves on **Create**, because its id names the file. |
| Publish | **Publish** on a document, **Publish N changes** on a collection, **Publish** on the dashboard for all collections, or select documents and publish those. |
| Schedule | The arrow next to **Publish** opens **Schedule…**. The on-screen draft publishes at the date and time you pick. If you save again before then, the schedule fails, so unreviewed changes never publish. See [Scheduling](https://vitehub.dev/docs/content/scheduling#console). |
| Undo a change | **History** lists a document's saves and publishes. One person's saves in a row show as one entry, such as **Saved · 12 edits**, that expands. Open one to compare it with the saved draft, then restore it as a new draft. Invalid versions still open. On wide screens, the side panel shows History or the body's outline. |
| Create and delete | **New** starts at the title. The id follows the title until you edit it. **Delete** removes the document from the draft. It stays published until you publish the deletion. |

## Fields as properties

Each field is a row built from its JSON Schema:

| Schema | Input |
| --- | --- |
| `string` | Text input. A `maxLength` over 200 gets a text area, where <kbd>⌘</kbd> <kbd>Enter</kbd> saves. The `title` field (or `name`, `label`, `heading`) is the page title above the rows. |
| `string` with `format: 'date'` | Date field with a calendar, stored as `YYYY-MM-DD`. |
| `string` with `format: 'date-time'` | Date and time fields in UTC, stored as an ISO string. Zod date fields such as `z.coerce.date()` use this. |
| `enum` | Select. |
| `number`, `integer` | Number input with `minimum` and `maximum`. |
| `boolean` | Switch. |
| `array` of strings | Tag input. |
| `array` of any other shape, such as objects or dates | A list with one row per item. An object item shows its `label`, `title`, or `name` and opens to its fields. Rows move up, move down, or are removed. **Add item** adds one. |
| `object` with `properties` | A one-line summary of the filled fields, such as **Label** Book a demo **To** /demo, that expands to the nested fields. |
| `object` with `src` and `alt` strings | An image. The summary shows a thumbnail and alt text, and the expanded fields a preview. The Console loads `src` from its own origin, so images on another origin show an icon. |
| A Blob reference (`x-vitehub-blob`), such as `image()` or `file()` | A thumbnail and file name with **Replace** and **Remove**, which open the [media picker](https://vitehub.dev/docs/content/console#pick-media-for-documents). An image also shows its alt text, which edits the alt text stored with the file. Without Blob, the pathname shows read-only. |
| Anything else | A JSON text area. |

A field without a Standard JSON Schema, such as a Valibot validator, has the schema `{}` and gets the JSON text area. So does a list of objects without `properties`. Empty optional fields are removed before the save, also in list items, so an empty input never saves `""` over a missing value.

## Saves never overwrite newer work

Each save sends the digest of the version you opened. If someone else saved in the meantime, Content returns `WORKSPACE_CONFLICT`. Saving pauses, the header reads **Not saved · newer version**, and a toast offers **Compare**. The comparison shows both versions. Choose **Overwrite with mine** to save over the version you compared, or **Load theirs**. **Keep editing** closes it and keeps your unsaved changes.

An invalid field still saves, so you lose nothing. The editor shows each message next to its field, and the header links to the first one. **Publish** stays off with "Fix 2 fields to publish" until they validate. The list and dashboard show the issue count, and **Publish all** leaves these drafts out.

## Editing together

The Console shows who has a document open, and gives one tab at a time the [edit lease](https://vitehub.dev/docs/content/editing-together). It needs `contentSessionsSchema` in the Workspace history Database. With Realtime on, Markdown documents open in a [live session](https://vitehub.dev/docs/content/editing-together#live-editing) where everyone edits at once. The lease applies only without live editing.

- **Avatars.** The header shows up to three people, then `+N`. Hover one for `Ana · Editing` or `Ana · Viewing`. List rows show one small avatar, such as `Ana is editing`. The dashboard lists them under **Open now**.
- **First edit.** Opening does not lock a document. The first keystroke claims the lease, and the edit stays on screen meanwhile. Saving starts once this tab holds it.
- **Someone else is editing.** The dialog says `Ana is editing this page`, with **Open read-only** and **Take over**. <kbd>Esc</kbd> opens it read-only. People without write access never see **Take over**.
- **Read-only.** A line above the title says `Read-only · Ana is editing`, with **Take over**. When Ana leaves, it says `Ana stopped editing`, with **Reload and edit**.
- **Taken over.** The former editor sees `Ben took over · Your changes up to 10:42 are saved`, with **Compare** and **Take back**. Edits that could not save show as `1 edit wasn't saved`, with **Copy**.
- **Another tab of yours.** A second tab says `You're editing this in another tab` and offers the same choices.
- **Updates.** A page without unsaved edits reloads when someone else saves. A page with unsaved edits keeps them, and the next save shows the comparison.
- **Unreachable.** If the Console cannot check sessions, the header says `Can't check who else is editing` and the page stays editable. Saves still refuse to overwrite a newer version.

The editor reports every 15 seconds, or 60 while hidden. After 15 minutes without input, the tab frees the lease, and the next keystroke claims it again if free. Closing the tab frees it at once.

## Preview the page

For a collection with a `url`, the window button in the editor header opens the page in a side browser, as in an IDE. Its toolbar has the address, **Draft** or **Published**, **Desktop** or **Mobile**, **Reload**, and **Open in a new tab**. Drag the divider, or focus it and use the arrow keys, to resize. <kbd>Home</kbd> and <kbd>End</kbd> make the preview widest or narrowest. On a phone the preview covers the editor, and **Editor** goes back.

- **Draft** renders the unsaved fields and body through your routes with a [preview frame](https://vitehub.dev/docs/content/preview#preview-frames). Only this document is a draft. The rest of the page is published. Nothing is stored. Same-site redirects, such as locale or sign-in, keep the document on screen. A redirect to another site, or too many, shows **Retry**.
- **Published** loads the page as a guest sees it, with `?vitehub-content-published`, also after same-site redirects. A [preview cookie](https://vitehub.dev/docs/content/preview) does not make it a draft, and stays for your other tabs.
- **Click to edit.** Elements with [`contentField()`](https://vitehub.dev/docs/content/server-api#field-addresses) attributes select their field in the editor. In **Draft**, top-level text fields, such as the title, change in place. <kbd>Enter</kbd> ends the edit, and <kbd>Esc</kbd> undoes it. Focusing a field in the editor outlines it in the page.

The page must allow a frame from its own origin. A page that sends `X-Frame-Options: DENY` or `frame-ancestors 'none'` cannot show in the side browser.

## Translations

A collection with [`locales`](https://vitehub.dev/docs/content/configure#locales) shows the locales next to the title, source locale first, such as `EN ES`. A dot gives the state of each translation: green when it is up to date, yellow when the source changed after it, and empty when it is not translated yet. Hover a locale for its name and state. List rows name the translations that need work, such as `ES out of date` or `ES missing`.

- **Not translated yet.** The locale opens with the source version and says so. Your first edit saves the translation in its own file, such as `docs/es/guide.md`, and records the source version on screen. If someone changed the source in the meantime, the translation shows as out of date at once.
- **Out of date.** A line above the title says the source changed after the translation, with a button that opens the source. Saves keep the translation out of date, so a typo fix does not hide a change in the source.
- **Mark as up to date.** The button on that line shows the current source version. Confirm, and the save records that version as the source of the translation. If the source changed again while you checked it, the dialog shows the newer version and the translation stays out of date.
- **Publish.** **Publish** publishes the translation on screen. **Schedule…** stays on the source locale.
- **Not yet for translations.** Live editing, the edit lease, Local only, and the side browser work on the source locale. Saves of a translation still refuse to overwrite a newer version.

## Edit locally first

The editing menu in the header switches between **Collaborative** and **Local only**. It is separate from the preview's Draft and Published views.

- **Collaborative** edits the shared draft. It saves as you type, in the live session when Realtime is on.
- **Local only** keeps your edits in this tab. They never save or reach the live session, and nobody else sees them. A reload keeps them. Closing the tab asks first. The Draft view shows them as **Local draft**.
- **Apply to shared draft** saves them over the shared draft they started from. Edits made during the save stay local. If someone saved the shared draft since, nothing is saved, and a comparison opens with **Overwrite with mine**, **Discard mine**, and **Keep editing locally**. With one editor at a time, Apply borrows the edit lease for the save, even in read-only mode. It never takes the lease over: while someone else edits, the banner says who, and **Retry** applies when they stop.
- **Discard** drops them. Switching to Collaborative or leaving with local edits asks you to apply or discard first.
- Switching to Local only in a live session makes the room save first. Your local edits start from that version. Fields or text typed during the save stay local.
- If someone deletes the shared draft, your local edits stay, even after a reload. The banner says so and offers **Copy**, **Discard**, and **Apply to shared draft**. Apply then opens a comparison, where **Create again from mine** saves your edits as a new draft. Publish is off until you apply or discard.
- **Publish shared draft** publishes the shared draft, never local edits. It shows what would go live, and refuses if the shared draft changed during review. If the site also changed, the comparison shows both. **Keep the shared draft** and **Use the site version** save only that one, and refuse if either changed again. Local edits stay until you apply them.

## The body round-trips

The rich editor edits the Markdown body through Comark. Opening a document or switching between Rich and Source writes nothing, so the text stays byte for byte until someone edits it. After an edit, the editor writes canonical Markdown, so `*` bullets can become `-`. Marks around the same text are equal to the editor, so `**[a](/x)**` can become `[**a**](/x)`.

If a body uses Markdown the rich editor would drop, such as a footnote definition the base parser drops, Rich mode is read-only for it and says so. Edit it in Source. Components round-trip through the shared Comark UI schema without a collection declaration.

Images from the `/` menu, or pasted or dropped into the body, go through the [media picker](https://vitehub.dev/docs/content/console#pick-media-for-documents). The title is the page heading, so start the body with its first paragraph, not a `# Title` that repeats it.

## Media library

**Media** at `/_vitehub/content/-/media` shows the files of the Blob Store that [`blob.serve`](https://vitehub.dev/docs/blob/configure) serves, or the `default` store if none is served. It appears when Blob is on. Every change goes through [`blob.media`](https://vitehub.dev/docs/blob/media), so the library and your server code see the same records.

| Task | How |
| --- | --- |
| Browse | Folders and breadcrumbs, files in a grid or list. Thumbnails are small [variants](https://vitehub.dev/docs/blob/media#image-variants) over the image's placeholder color. The URL holds the folder and open file, such as `?folder=posts&file=posts/cover.jpg`. |
| Find | Search by file name in the open folder and its subfolders. Filter by type: images, videos, audio, documents, or other. |
| Upload | Drop files on the library, or choose **Upload**. Files upload three at a time with progress. A failed file stays queued with its reason and **Retry**. Names become URL-safe (`Launch Day.PNG` is `launch-day.png`), and an existing name gets `-2`. Identical bytes reuse the stored file. |
| Organize | **New folder**, and **Rename or move…** on a file or folder. Select files with their checkbox, <kbd>⌘</kbd>-click, or <kbd>Shift</kbd>-click for a range, then **Move…** or **Delete**. <kbd>Esc</kbd> clears the selection. |
| Describe | Open a file for details. Alt text and caption save as you type. It shows dimensions, size, format, upload date, pathname, and a URL to copy. |
| Set the focal point | Click or drag on the image, or focus the marker and use the arrow keys. Previews at 1:1, 4:5, 16:9, and 1.91:1 crop around it like the serve route. |
| Art-direct | **Crops** lists named crops, such as `mobile` at 4:5. **Add crop** takes a name and an aspect. A crop cuts the original around the focal point until you **Upload replacement**, an image made for that size, such as a portrait version for phones. **Use the focal point** removes the replacement. Sites ask for a crop with `?crop=mobile` or [`responsiveImage({ art })`](https://vitehub.dev/docs/blob/media#art-direction). |
| See where a file is used | **Used in** lists and links the drafts and published documents whose fields or body use the file. Moving or deleting a used file first warns with this list. |

Moves and deletes do not rewrite documents. A document keeps the old pathname until someone picks the file again.

## Pick media for documents

The editor picks media from the library:

- **Image…** in the <kbd>/</kbd> menu opens the library in a dialog. Pick or upload images, then **Insert**. With one image selected, the dialog shows its alt text. Editing it saves it to the file.
- Images pasted or dropped into the body upload at once to the folder you last opened in the library.
- A Blob reference field, such as `image()` or the [SEO](https://vitehub.dev/docs/content/seo#seo-fields) social image, opens the same dialog and stores `{ pathname, contentType, size }`.

The body stores the Blob pathname, such as `![A field at sunrise](posts/cover.jpg)`, not a URL, so documents keep working when the serve route or host changes. The editor shows it through the served URL. When your site renders the Markdown, turn a `src` without a scheme or leading `/` into the served URL, such as `/api/_vitehub/blob/posts/cover.jpg`, or [`responsiveImage()`](https://vitehub.dev/docs/blob/media#responsive-images) output.

### Who may change media

Media is part of the Content section, so a user needs the `content` section in `console.authorize`, not the Blob section. Blob still applies [`blob.serve.authorize`](https://vitehub.dev/docs/blob/configure) to every thumbnail and preview, and stores every change.

All collections share media, so access follows [`authorize` in `defineContent()`](https://vitehub.dev/docs/content/configure#access):

| Content access | Media |
| --- | --- |
| Read any collection | Browse and pick. |
| Write any collection | Also upload, create folders, and change alt text, captions, focal points, and crops. |
| Publish any collection | Also move, rename, and delete files and folders. These change published pages at once, without a publish. |

In the playground, writers upload and describe files, and editors also move and delete them. A request without access returns `403` with `MEDIA_FORBIDDEN`.

MCP agents cannot use the library, because it is a Console page. To let an editor's agent list and upload media, also grant the library's Blob store, such as `'blob:media'` when `blob.serve.store` is `media`. The agent then uses `blob_list`, `blob_put`, and `blob_media` on that store only. Other stores, such as a private Content store, return `403`. See [Grant one Blob store](https://vitehub.dev/docs/development/console#grant-one-blob-store).

## Publishing publishes what you reviewed

Every publish sends the documents and draft digests the editor showed, through [`publish({ expect })`](https://vitehub.dev/docs/content/server-api#publish-what-was-reviewed). **Publish** on a document saves pending edits, then sends the on-screen draft. **Publish N changes** and **Publish N selected** send the drafts the list loaded.

If someone saved one of those drafts after it loaded, Content publishes nothing and returns `WORKSPACE_CONFLICT` with the changed documents. The list names them. Choose **Refresh**, review the latest drafts, and publish again. The document editor loads the newer draft for you.

If a draft does not validate, for example after a field changed in `server/content.ts`, publishing returns `CONTENT_INVALID` and publishes nothing. The list names the document, and the editor highlights its fields. Fix them, save, and publish again.

## Give editors only the Content section

Two policies decide what an editor can do:

1. [`console.authorize`](https://vitehub.dev/docs/development/console#limit-a-user-to-some-sections) decides which Console sections a request may use. Return `{ sections: ['content'] }` for editors.
2. [`authorize` in `defineContent()`](https://vitehub.dev/docs/content/configure#access) decides what a user may do with each collection. The Console calls `content.can()` with the signed-in user before each read, save, delete, restore, and publish.

### Nuxt

```ts [nuxt.config.ts]
export default defineNuxtConfig({
  modules: ['vite-hub/nuxt'],
  vitehub: {
    preset: 'node',
    auth: true,
    database: true,
    workspace: true,
    console: { auth: 'app', authorize: './server/console-authorize.ts' },
  },
})
```

### Nitro

```ts [vite.config.ts]
import { nitro } from 'nitro/vite'
import { defineConfig } from 'vite'
import { vitehub } from 'vite-hub'

export default defineConfig({
  plugins: [
    vitehub({
      preset: 'node',
      auth: true,
      database: true,
      workspace: true,
      console: { auth: 'app', authorize: './server/console-authorize.ts' },
    }),
    nitro(),
  ],
})
```

### Vite

```ts [vite.config.ts]
import { defineConfig } from 'vite'
import { vitehub } from 'vite-hub'

export default defineConfig({
  plugins: [
    vitehub({
      preset: 'node',
      auth: true,
      database: true,
      workspace: true,
      console: { auth: 'app', authorize: './server/console-authorize.ts' },
    }),
  ],
})
```

```ts [server/console-authorize.ts]
import { defineConsoleAuthorize } from 'vite-hub/console/auth'

export default defineConsoleAuthorize(({ user }) => {
  if (user?.role === 'admin') return true
  if (user?.role === 'editor' || user?.role === 'writer') return { sections: ['content'] }
  return false
})
```

```ts [server/content.ts] fragment
export const content = defineContent({
  workspace: 'site',
  collections: { posts },
  // Writers save drafts. Only editors publish.
  authorize: ({ user, action }) => {
    if (user?.role === 'editor') return true
    if (user?.role === 'writer') return action !== 'publish'
    return false
  },
})
```

A writer sees the posts and saves drafts, with no publish buttons. A writer's publish request returns `403` with `CONTENT_FORBIDDEN`. Other Console sections return `403`, and the navigation shows only Content.

The Console passes the user that its access mode signed in:

| `console.auth` | `user` in `content.can()` |
| --- | --- |
| `'app'` or a session-based Console Auth | The signed-in user. |
| `false` | `null`. Use `console.authorize` to decide who reaches the section. Let `content.authorize` allow `null` only if every such request may edit. |
| Cloudflare Access | `null`. |

Saves, restores, deletes, and publishes record the user's `name`, `email`, or `id` as the revision author, shown in History.

## Playground

`playground/content` in the ViteHub repository is a full app with app Auth, the Blob + Database Store, two collections, and three users: an admin, an editor limited to Content, and a writer who cannot publish. Its README shows how to run it.

## Limits

- The section loads `server/content.ts` on the first Content request, not at server start.
- Document requests accept bodies up to 1 MiB.
- The list reads all of a collection's documents into memory, like [`list()`](https://vitehub.dev/docs/content/server-api). The dashboard and search read each collection's state once per request the same way.
- Recent activity shows the last 20 revisions, from at most 1,000 scanned per ref.
- The dashboard and search publish one collection at a time. If a draft moved after the page loaded, that collection publishes nothing and the Console asks you to refresh.
- History shows a document's last 20 saves and last 20 publishes, then older saves on request. Content scans at most 1,000 revisions per page.
- Uploads take files up to 32 MB per request. Hosts can set a lower limit, such as 4.5 MB on Vercel Functions.
- Media search scans at most 5,000 files below the open folder and shows at most 60 matches. Open a folder to narrow it.
- **Used in** reads every document, on draft and published, of each collection the user may read. It finds bodies through the collection's [search fields](https://vitehub.dev/docs/content/configure#define-collections), which include the body by default. It lists only documents the user may read, so the move or delete warning leaves out other documents that use the file. It does not tell which Blob Store a reference names.
- Media edits are last-writer-wins, like [`blob.media`](https://vitehub.dev/docs/blob/media#consistency).
- A live preview of the page is not available yet.
- Autosave starts only after a document exists. Leaving the page right after typing saves first. Closing the tab asks.
- The Nuxt module registers the page, but this editor is verified only in the Vite Console. Content supplies the Comark UI implementation and its editor dependencies.

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

- [Overview](https://vitehub.dev/raw/docs/content.md)
- [Get started](https://vitehub.dev/raw/docs/content/get-started.md)
- [Configure](https://vitehub.dev/raw/docs/content/configure.md)
- [Server API](https://vitehub.dev/raw/docs/content/server-api.md)
- [Agent capability](https://vitehub.dev/raw/docs/content/agent-capability.md)
- [Limits and errors](https://vitehub.dev/raw/docs/content/limits-and-errors.md)
- [Draft preview](https://vitehub.dev/raw/docs/content/preview.md)
- [Console editor](https://vitehub.dev/raw/docs/content/console.md) (this page)
- [Editing together](https://vitehub.dev/raw/docs/content/editing-together.md)
- [Scheduling](https://vitehub.dev/raw/docs/content/scheduling.md)
- [SEO](https://vitehub.dev/raw/docs/content/seo.md)
- [CLI](https://vitehub.dev/raw/docs/content/cli.md)

Next: [CONTENT_R0010](https://vitehub.dev/raw/docs/content/diagnostics/content_r0010.md)

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