# Content

Turn Markdown files into pages you can read, list, and search, and let people edit and publish them.

Hosts: Node, Docker, Cloudflare, Vercel, Netlify, Deno.

```ts [server/content.ts]
import sqlite from 'comark-content/database/sqlite-node'
import sqliteFullTextSearch
  from 'comark-content/plugins/sqlite-full-text-search'
import { defineContent } from 'vite-hub/content'
import { glob } from 'vite-hub/source'

export const content = defineContent({
  // Keep a search index in SQLite
  plugins: [
    sqliteFullTextSearch({ database: sqlite() }),
  ],
  // Every Markdown file in your docs folder
  sources: {
    docs: glob({ cwd: 'docs', include: '**/*.md' }),
  },
})
```

```md [docs/intro.md]
# Hello from Content

This file is in your project.
Content reads it as the page /intro.
```

```ts [server/api/intro.get.ts]
import { defineEventHandler } from 'h3'
import { content } from '../content'

// One page, and a menu of every page
export default defineEventHandler(async () => {
  return {
    page: await content.get('/intro'),
    menu: await content.navigation(['docs']),
  }
})
```

```bash [CLI]
pnpm vitehub content status
pnpm vitehub content diff posts hello
pnpm vitehub content publish --collection posts --id hello
```

```ts [server/api/search.get.ts]
import { defineEventHandler, getQuery } from 'h3'
import { content } from '../content'

// Search every page: /api/search?q=hello
export default defineEventHandler(async (event) => {
  const { q } = getQuery(event)
  return content.search(['docs'], String(q ?? ''))
})
```

```ts [app/utils/content.ts]
import {
  createContentClient,
} from 'vite-hub/content/client'

// Read pages from the browser.
// It calls the /api/content route for you.
export const content = createContentClient()

// await content.get('/intro')
// await content.navigation()
```

Search uses optional `comark-content` plugins. [Search configuration](https://vitehub.dev/docs/content/configure#providers) shows how to install them and where they store data. You need no Comark setup to read and render Markdown.

### [Write pages in Markdown](https://vitehub.dev/docs/content/get-started#define-and-read-content)

Point Content at a folder of Markdown files. It reads the headings and body of each page.

### [Read pages from a route](https://vitehub.dev/docs/content/server-api#runtime-api)

`content.get()` returns one page. `content.navigation()` builds a menu from all pages.

### [Search every page](https://vitehub.dev/docs/content/configure#providers)

Add the full-text search plugin. It keeps its index in SQLite.

### [URLs, head tags, and a sitemap](https://vitehub.dev/docs/content/seo)

`seo()` fields, `contentHead()` for any framework, and generated `/sitemap.xml` and `/robots.txt`.

### [Publish reviewed drafts on a schedule](https://vitehub.dev/docs/content/scheduling)

`content.schedule()` publishes the reviewed version later. A Schedule Definition runs it on every host.

### [One editor at a time, and everyone sees who](https://vitehub.dev/docs/content/editing-together)

See who is editing. While one person holds the edit lease, writes from others fail with `CONTENT_LEASE_HELD`.

### [Edit, publish, and schedule from the terminal](https://vitehub.dev/docs/content/cli)

`vitehub content` lists, edits, and diffs drafts in the running dev server, then publishes or schedules what you reviewed.

### [Read pages from the browser](https://vitehub.dev/docs/content/server-api#client)

`createContentClient()` reads the `/api/content` route that ViteHub adds for you.

### [Edit, then publish](https://vitehub.dev/docs/content/configure#document-collections)

People edit collection pages in your app. Each save is a draft. Visitors see only what you publish.

### [One preset stores the collections](https://vitehub.dev/docs/cms)

`extends: cms` adds the Workspace, its history tables, and a Database if the app has none.

### [Let an Agent draft, publish, and schedule documents](https://vitehub.dev/docs/content/agent-capability)

`content()` gives an Agent typed tools for each collection and singleton. Your `authorize` policy decides what it may read and change. Publishing asks for approval.

### [Check every field](https://vitehub.dev/docs/content/configure#fields)

Give each front matter field a rule, such as "title is not empty". A save with a bad field fails.

Use Content to parse, query, search, and serve Markdown or other Source content through Comark. It is for application content, not arbitrary code execution.

Use the [Content CLI](https://vitehub.dev/raw/docs/content/cli.md) (`vitehub content list|show|status|diff|edit|publish|schedule --json`) to read, edit, publish, and schedule documents in a running dev server. `edit` honours edit leases unless `--override-lease`.

Keep content definitions and Source access explicit. Validate front matter and route parameters before using a result in a response.

Prove one local content query, one filtered or paginated query, and one served response. Include missing and malformed content cases.

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

- [Overview](https://vitehub.dev/raw/docs/content.md) (this page)
- [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)
- [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_R0001](https://vitehub.dev/raw/docs/content/diagnostics/content_r0001.md)

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