# Content SEO

Content handles the SEO parts that depend on your documents: each document's URL, its search and social text, and the sitemap. Your pages render the tags. Content returns them in the `useHead()` shape, so any framework or server route can use them.

| Part | What it does |
| --- | --- |
| [`url`](https://vitehub.dev/docs/content/seo#document-urls) | Each document's public URL, as `document.url`. |
| [`seo()`](https://vitehub.dev/docs/content/seo#seo-fields) | Per-document title, description, social image, canonical URL, and `noindex`. |
| [`contentHead()`](https://vitehub.dev/docs/content/seo#head-tags) | Head tags from a document, its `seo()` values, and site defaults. |
| [`defineContent({ seo })`](https://vitehub.dev/docs/content/seo#sitemap-and-robotstxt) | Generated `/sitemap.xml` and `/robots.txt`. |
| [`seo: { rss }`](https://vitehub.dev/docs/content/seo#rss-feed) | A generated `/rss.xml` with the newest pages, dated from their history. |
| [`seo: { mcp }`](https://vitehub.dev/docs/content/seo#page-mcp-server) | A read-only MCP server at `/mcp`, so agents can list and read your pages. |
| [`seo: { markdown, llms }`](https://vitehub.dev/docs/content/seo#markdown-for-agents) | Markdown copies of each page, `/llms.txt`, `/llms-full.txt`, and `/sitemap.md`. |
| [Console SEO group](https://vitehub.dev/docs/content/seo#console) | Counters, fallbacks, and search and social previews. |

With `authorize`, every generated SEO route except `/robots.txt` asks it for `read` first, as `/api/content/**` does, and answers with `Cache-Control: private, no-store`. Set `access: 'public'`, or return `true` for `action: 'read'`, to serve them to crawlers and agents. See [Public access](https://vitehub.dev/docs/content/configure#public-access).

## Document URLs

Set `url` on a collection or singleton to give its documents a public URL. A pattern replaces `:id` with the document id and `:<field>` with a text or number field:

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

export default defineContent({
  workspace: 'site',
  collections: {
    posts: documents({ path: 'posts/**/*.md', url: '/blog/:id', fields: { title: z.string(), seo: seo() } }),
    docs: documents({ path: 'docs/**/*.md', url: ({ id }) => id === 'index' ? '/docs' : `/docs/${id}`, fields: { title: z.string() } }),
    home: singleton({ path: 'home.md', url: '/', fields: { title: z.string() } }),
  },
})
```

`get()`, `list()`, `save()`, and the Console return `url` for a routable collection. Values are encoded per path segment, so the id `2026/hello` becomes `/blog/2026/hello`. An empty pattern field, or a function that returns `null`, gives `url: null`: the document has no page. Without `url`, reads leave the key out and `collection.routable` is `false`. [`content.resolve(path)`](https://vitehub.dev/docs/content/configure#find-the-document-of-a-page) uses `url` to find a page's document.

A pattern must start with `/` and name only `:id` and defined fields. Otherwise loading the definition throws `CONTENT_R0006`.

In a collection with [locales](https://vitehub.dev/docs/content/configure#locales), a pattern without `:locale` puts `/<locale>` before the URL of every locale but the source locale, so `/docs/:id` gives `/docs/guide` and `/es/docs/guide`. Write `:locale` in the pattern, such as `/:locale/docs/:id`, to place the locale yourself. A `url()` function receives `{ id, data, locale }`.

### Source URLs

A read-only Source (files Content does not edit) gets a `url` from `contentSource(input, { url })`. A Source document's id is its path without the leading slash and extension: `glob({ cwd: 'content' })` reads `content/guides/start.md` as `guides/start`. A `:<name>` in the pattern reads a frontmatter value.

```ts [server/content.ts]
import { contentSource, defineContent } from 'vite-hub/content'
import { glob } from 'vite-hub/source'

export default defineContent({
  source: contentSource(glob({ cwd: 'content', include: 'guides/*.md' }), { url: '/:id' }),
  seo: { sitemap: true },
})
```

A Source `url` adds its documents to the [sitemap](https://vitehub.dev/docs/content/seo#sitemap-and-robotstxt) and gives them [Markdown copies](https://vitehub.dev/docs/content/seo#markdown-for-agents), but Source reads do not return `document.url`. `content.resolve()` and `seo()` fields work only with collections.

## SEO fields

`seo()` is a normal field. Add it to collections whose pages need their own search and social text:

```ts [server/content.ts] fragment
import { z } from 'zod'
import { image, seo } from 'vite-hub/content'
import { documents } from 'vite-hub/content/collections'

const posts = documents({
  path: 'posts/**/*.md',
  url: '/blog/:id',
  fields: { title: z.string(), summary: z.string().optional(), seo: seo({ image: image() }) },
})
```

| Key | Type | Falls back to |
| --- | --- | --- |
| `title` | `string` | The document `title`, `name`, `label`, or `heading`. |
| `description` | `string` | The document `description`, `summary`, or `excerpt`, then the site default. |
| `image` | URL, or a Blob reference with `seo({ image: image() })` | The site default image. |
| `canonical` | Absolute URL, or a path that starts with `/` | The document `url`. |
| `noindex` | `boolean` | `false`. |

The field and each key are optional. Unknown keys fail validation, so a save catches a typo such as `descripton`. Long text still validates. Search results show about 60 title characters and 50 to 160 description characters. The field's JSON Schema has those lengths in `x-vitehub-seo` for forms and tools.

`seo()` is a record of validators, not a Zod or Valibot object, because those reject a Blob `image()`. By default the social image is an absolute or root-relative URL, such as `/og/home.png`. Pass `image()` from `vite-hub/content` to store a [Blob reference](https://vitehub.dev/docs/blob/server-api) instead. Its issues come back under `seo.image`.

Values are stored as nested YAML in Markdown frontmatter, or nested JSON or YAML in [data files](https://vitehub.dev/docs/content/configure#data-files).

## Head tags

`contentHead(document, options)` returns `{ title, meta, link, script?, htmlAttrs? }`. It reads `seo()` values, then the document's fields, then `defaults`. It needs no framework and runs on the server or in the browser. Import it from `vite-hub/content`, or `vite-hub/content/client` in browser code.

```vue [pages/blog/[...id].vue]
<script setup lang="ts">
import { contentHead } from 'vite-hub/content/client'

const route = useRoute()
const { data: post } = await useFetch(`/api/posts/${route.params.id}`)
const { data: settings } = await useFetch('/api/settings')

useHead(computed(() => contentHead(post.value, {
  site: { url: 'https://vitehub.dev', name: settings.value?.data.title },
  defaults: { description: settings.value?.data.description, image: settings.value?.data.socialImage },
})))
</script>
```

Nuxt has `useHead()` built in. In a Vue app, install `@unhead/vue`. In a plain server route, render the tags yourself, as `server/routes/blog/[...id].get.ts` in the Content playground does.

| Option | Description |
| --- | --- |
| `site.url` | Public origin for absolute canonical, `og:url`, and image URLs. |
| `site.name` | `og:site_name`, and the default title template `%s · <name>`. |
| `rss` | `true` adds an RSS discovery link to `/rss.xml`. |
| `site.locale` | `og:locale`, such as `en_US`. |
| `defaults` | `{ title?, description?, image? }` fallbacks, often from a [settings document](https://vitehub.dev/docs/content/configure#singletons-and-data-files). ViteHub has no settings schema, so you map your fields. |
| `titleTemplate` | `'%s \| Docs'`, a function, or `null` for none. A document without a title uses the default title as is. |
| `collection` | The document's collection, such as `content.collection('posts')`, or its JSON form with `schema`. `contentHead()` finds the `seo()` field by its marker, whatever its name, and titles the page with `titleField`. |
| `field` | The field that holds `seo()` values. Defaults to the `seo()` field of `collection`, then to `seo`. |
| `resolveImage` | Turns an image value into a URL. By default, strings stay as they are, and a Blob reference of the `default` store becomes its [`blob.serve`](https://vitehub.dev/docs/blob/configure) URL, with its `route` and `publicBaseUrl`. The default reads the generated Blob config, so it works on the server. In the browser, or for signed or CDN URLs, pass your own. |
| `type` | `og:type`. Defaults to `article` for a document with a URL, else `website`. |
| `rss` | `true` adds `<link rel="alternate" type="application/rss+xml">` for [`/rss.xml`](https://vitehub.dev/docs/content/seo#rss-feed), titled with `site.name`. `{ href, title }` links another feed. |
| `markdown` | `true` adds `<link rel="alternate" type="text/markdown">` for the [Markdown copy](https://vitehub.dev/docs/content/seo#markdown-for-agents) of a document with a URL, such as `/blog/hello.md`. Pass `{ prefix: '/raw' }` when `seo.markdown` has that prefix. |
| `jsonLd` | `true` adds an `Article` or `WebPage` JSON-LD script. You can pass your own object. `<` is escaped, so document text cannot close the script. |

The result has `description`, `robots: noindex` when set, Open Graph `og:title`, `og:description`, `og:type`, `og:url`, `og:image`, `og:site_name`, and `og:locale`, Twitter `summary_large_image` or `summary` card tags, and a `canonical` link. Empty tags are left out.

### Pages in several locales

A document from a collection with [locales](https://vitehub.dev/docs/content/configure#pages-in-each-locale) carries `locale`, and `get()` gives it `alternates`, the URL of each locale that has its own version. `contentHead()` reads both:

- `htmlAttrs: { lang }` is the locale of the version that the page shows. `useHead()` sets it on `<html>`.
- When the document has its own version in two or more locales, `link` has `{ rel: 'alternate', hreflang, href }` for each of them, and `hreflang: 'x-default'` for the source locale page.
- A page that shows the source locale because its locale has no translation (`fallback: true`) has `lang` of the source locale, and its canonical link points to the source locale page. `seo.canonical` still wins.

```ts fragment
contentHead(await docs.get('guide', { locale: 'es' }), { site: { url: 'https://vitehub.dev' } })
// htmlAttrs: { lang: 'es' }
// link: canonical https://vitehub.dev/es/docs/guide, alternate en /docs/guide, es /es/docs/guide, x-default /docs/guide
```

## Sitemap and robots.txt

Turn on the routes in `defineContent()`:

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

export default defineContent({
  workspace: 'site',
  collections: {
    posts: documents({ path: 'posts/**/*.md', url: '/blog/:id', fields: { title: z.string(), seo: seo() } }),
    home: singleton({ path: 'home.md', url: '/', fields: { title: z.string() } }),
  },
  seo: { site: 'https://vitehub.dev', sitemap: true, robots: { disallow: ['/_vitehub'] } },
})
```

| `seo` option | Description |
| --- | --- |
| `site` | Public origin for absolute URLs. Defaults to the origin of each request. |
| `sitemap` | `true` serves `/sitemap.xml`. |
| `robots` | `true` serves a `/robots.txt` that allows every crawler. `{ disallow }` keeps paths out. It names `/sitemap.xml` when the sitemap is on. |
| `rss` | `true`, or `{ title, description, limit }`, serves [`/rss.xml`](https://vitehub.dev/docs/content/seo#rss-feed). |
| `mcp` | `true`, or `{ name }`, serves a [page MCP server](https://vitehub.dev/docs/content/seo#page-mcp-server) at `/mcp`. |
| `dateLeases` | A shared atomic `LeaseStore` to coordinate Source date refreshes across server instances. See [RSS feed](https://vitehub.dev/docs/content/seo#rss-feed). |

In a collection with locales, the sitemap lists each published translation at its own URL, with `locale` on each entry. It leaves out pages that show the source locale as a fallback: their canonical link points to the source locale page.

The sitemap lists:

- Every published document with a URL in a routable collection, except documents with `seo.noindex` or a `seo.canonical` that points elsewhere. `lastmod` is its `updatedAt` on `published`. Drafts are never listed.
- Every document of a Source with a [`url`](https://vitehub.dev/docs/content/seo#source-urls). For a `github()` Source, `lastmod` is the date of the latest commit that changed the file, from [`content.history()`](https://vitehub.dev/docs/content/seo#rss-feed). Other Sources, and a `github()` Source without a GitHub token, have no `lastmod`. A Source without `url` is not listed.

One sitemap holds 50,000 URLs. Above that, `content.sitemap()` throws `CONTENT_R0009` and does not return a partial sitemap.

To list Content pages together with the other pages of your app, use [`vitehub({ seo: { sitemap: true } })`](https://vitehub.dev/docs/frameworks-hosts/sitemap) instead. It serves `/sitemap.xml` and `/robots.txt` for the whole app, so Content adds neither route.

Like `/api/content/**`, the `vitehub()` Vite plugin and the Nuxt module generate both routes from the `defineContent()` call in `server/content.ts`, without running it. They do so when `seo` sets `sitemap` or `robots` to anything but literal `false`. The routes run on Nitro 3, in Vite and in Nuxt 5, and on every host. Your own server route at `/sitemap.xml` or `/robots.txt` fails the build. A file in `public/` is served first.

Check the output from code:

```ts [server/utils/seo-check.ts]
import content from '../content'

export async function checkSeo() {
  await content.sitemap()  // [{ collection: 'posts', id: 'hello', loc: 'https://vitehub.dev/blog/hello', lastmod }]
  content.robots()         // 'User-agent: *\nDisallow: /_vitehub\n\nSitemap: https://vitehub.dev/sitemap.xml\n'
}
```

In another server, mount `defineContentSitemapHandler(content)` and `defineContentRobotsHandler(content)` yourself. Each one returns a Fetchable route, `{ fetch(request) }`, that Nitro and H3 accept as a route handler. You can also call `fetch(request)` directly. `renderContentSitemap(entries)` renders entries as sitemap XML, for example to add pages that are not Content documents.

## RSS feed

`seo: { rss: true }` serves `/rss.xml`, an RSS 2.0 feed of the pages that the sitemap lists, Markdown pages only. The newest page comes first, by the date of its latest `content.history()` entry: the last publish of a collection document, or the last commit that changed the file of a `github()` Source page.

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

export default defineContent({
  workspace: 'site',
  collections: {
    posts: documents({ path: 'posts/**/*.md', url: '/blog/:id', fields: { title: z.string(), description: z.string() } }),
  },
  seo: { site: 'https://vitehub.dev', rss: { title: 'ViteHub blog', limit: 30 } },
})
```

| `rss` option | Description |
| --- | --- |
| `title` | The feed title. Defaults to the host name of the site. |
| `description` | The feed description. Defaults to the title. |
| `limit` | The newest pages to list, from 1 to 500. Defaults to 20. |

Each item has the page `title` (the `seo()` title, else the title field), its absolute `link`, the `description` field when there is one, a `guid` that is the link, so an edited page is not a new item, and a `pubDate`. A `github()` Source page without a GitHub token has no history. It uses its `date` frontmatter field, and without one it has no `pubDate` and goes last.

Content keeps the dates of `github()` Source pages in memory and in ViteHub KV per head commit, so requests that can read the cached set make no GitHub request. The first feed or sitemap after the head commit moves asks GitHub only for the pages that changed since the last dates: one compare request, then one GraphQL request per 150 changed pages. With no earlier dates, such as on the first deploy, it asks for every page: 2,600 pages cost 18 GraphQL requests, which fits the 50 subrequests of a free Cloudflare Worker. A compare that GitHub cannot list in full (300 files or more, or a head that does not descend from the last one) also reads every page. Collection dates come from the Workspace and cost no request.

No feed or sitemap request waits for those GitHub requests when the host has `waitUntil`, as Cloudflare Workers and Vercel do. Until the dates of the new head are ready, the routes answer at once with the dates of the previous head, and with `Cache-Control: no-store` so no cache keeps that answer. A new page has its `date` field, else no date. Content computes the new dates after the response. The push webhook computes them right after it moves the head, so most requests never see old dates. Without `waitUntil`, such as on plain Node, the first request after a head move waits for the dates. In your own route, pass `getStandardContext(request).waitUntil` as `content.rss({ waitUntil })` or `content.sitemap({ waitUntil })`.

Blocking reads, background reads, and webhook warming share in-flight work within one Content instance. For several instances, set `seo.dateLeases` to a shared atomic `LeaseStore`, such as `createSqlLeaseStore(client)` from `@vite-hub/runtime`. Every reader and webhook instance must use the same authority. The SQL client must implement the runtime `LeaseSqlClient` contract against a shared database. `createMemoryLeaseStore()` coordinates only one process; it is not a distributed authority.

A lease holds one Source/head for 60 seconds. A successful refresh keeps it until expiry so the KV cache can propagate. A failed refresh releases it for retry. An instance that does not get the lease serves cached dates or none, even without `waitUntil`; later requests see the new dates when KV exposes them. A failed lease acquisition logs a warning and serves the same fallback without starting GitHub work. A refresh that runs longer than the lease can overlap a later refresh. Cloudflare KV has no atomic acquire operation and cannot provide this lock. Without `dateLeases`, each instance can compute the same dates; route feed, sitemap, and webhook refreshes through one instance when a shared authority is not available.

Add the feed to your pages with `contentHead(document, { rss: true })`. `content.rss()` returns the same XML. ViteHub generates `/rss.xml` like the sitemap; in another server, mount `defineContentRssHandler(content)`. `renderContentRss(channel, items)` renders your own items.

## Page MCP server

`seo: { mcp: true }` serves a read-only MCP server at `/mcp`. Agents connect to it to find and read your pages. It has the same two tools as the MCP server of a [docs site](https://vitehub.dev/docs/docs-site/configure), so an agent that knows one knows the other.

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

export default defineContent({
  workspace: 'site',
  collections: {
    posts: documents({ path: 'posts/**/*.md', url: '/blog/:id', fields: { title: z.string(), description: z.string().optional() } }),
  },
  seo: { site: 'https://vitehub.dev', mcp: { name: 'ViteHub blog' } },
})
```

| Tool | Returns |
| --- | --- |
| `list-pages` | `[{ title, path, description, url }]` for the Markdown pages that the sitemap lists. At most 1,000 per call; pass `offset` for the next ones. |
| `get-page` | `{ title, path, description, content, url }` for one page. `content` is its Markdown copy: the title as a heading, unless the body has its own, the description as a quote, then the body with absolute links. |

The tools read only what readers can see: published collection documents, and the files of the [head commit](https://vitehub.dev/docs/content/configure) of a `github()` Source. Drafts are left out. `list-pages` also leaves out `noindex` pages and pages whose `canonical` points elsewhere, but `get-page` reads them by path, as their `.md` copy does. `get-page` takes a path from `list-pages`, a full URL, or a path that ends in `.md`. For any other path it returns the tool error `[404] No page at <path>`. A page longer than 200,000 characters is cut, and the cut names the page URL.

`name` is the server name that MCP clients show. It defaults to the host name of `site`, or of the request. The server answers `POST` in the stateless JSON form of Streamable HTTP, revisions `2025-11-25` and `2025-06-18`, and refuses requests from a browser page on another origin.

`content.pages({ offset, limit })` and `content.page(path)` return the same data from code. ViteHub generates `/mcp` like the sitemap. The [app MCP server](https://vitehub.dev/docs/mcp/configure) also answers at `/mcp`. With both on, the build stops with [`SOURCE_B0010`](https://vitehub.dev/docs/source/diagnostics/source_b0010): give the app MCP server another `route`, such as `vitehub({ mcp: { route: '/mcp/app' } })`, or set `seo: { mcp: false }`. In another server, mount `defineContentMcpHandler(content)`.

## Markdown for agents

Agents read Markdown better than HTML. Two `seo` options serve your published Markdown documents as Markdown:

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

export default defineContent({
  workspace: 'site',
  collections: {
    posts: documents({ path: 'posts/**/*.md', url: '/blog/:id', fields: { title: z.string(), description: z.string().optional() } }),
  },
  seo: { site: 'https://example.com', llms: { title: 'Example', description: 'Notes about examples.' } },
})
```

| `seo` option | Description |
| --- | --- |
| `markdown` | `true` serves each page as Markdown at its URL plus `.md`, such as `/blog/hello.md`, and `/index.md` for `/`. The page URL also returns Markdown when the request sends `Accept: text/markdown` before `text/html`. `{ prefix: '/raw' }` also serves each copy below that folder, such as `/raw/blog/hello.md`, and the llms files link there. `{ pages: true }` also gives [every other app page](https://vitehub.dev/docs/content/seo#app-pages-as-markdown) a copy, converted from its HTML. |
| `llms` | `true`, or `{ title, description, details, sections, sort, headers, locales }`, serves `/llms.txt`, `/llms-full.txt`, and `/sitemap.md`. It also turns on `markdown`, because their links point at the `.md` copies. The title defaults to the host name. `details` is text under the description, such as rules for agents. `sections` adds sections of links, `[{ title, description?, links: [{ title, href, description? }] }]`, before the sections of pages, or is a function that builds them from `{ pages, markdown(page) }`. `sort(left, right)` puts the pages in the order of your app. `headers` adds response headers to the three files. `locales` sets the `title`, `description`, and `details` of each translated `llms-full.txt`, such as `{ es: { description: 'Guía para los invitados.' } }`. |

The copy starts with the document title, unless the body has its own heading, and its description as a quote. Root-relative links become absolute.

- `/llms.txt` follows the [llms.txt](https://llmstxt.org) format: the title, the description as a quote, the details, a link to `/llms-full.txt`, then one section per collection or Source, named by its `label`, with a link to the `.md` copy of each page and its description. Link titles are escaped, so a `]` in a title does not break the link.
- `/llms-full.txt` starts with the same title, description, and details, then has the copy of every page, home page first. Each page starts with `URL:` and its page URL, so an agent can cite it, and a `---` line separates the pages. A collection with `locales` keeps its source locale here, and each other locale in `/<locale>/llms-full.txt`, such as `/es/llms-full.txt`. `/llms.txt` links every one of these files.
- `/sitemap.md` lists every page, grouped by the first segment of its URL.

They list the same Markdown pages as the sitemap: published documents with a URL, and the Markdown files of Sources with a `url`, without `seo.noindex` or a `seo.canonical` that points elsewhere. Drafts and JSON and YAML documents are not listed. A `noindex` page still has its `.md` copy.

A Source sets how its pages show to agents with `contentSource(input, options)`:

| Option | Description |
| --- | --- |
| `url` | The page URL of each file, such as `'/docs/:id'`, or a function of `{ id, key, data }`, where `key` is the file path in the Source. Without it, the Source has no pages. |
| `label` | The `llms.txt` section of its pages. Defaults to the Source name in title case. |
| `seo` | A function of `{ id, key, data }` that returns `{ title, description, noindex, canonical }`, for frontmatter that does not use the `seo` field. |
| `markdown` | A function that renders the copy of a page from `{ id, key, path, text, title, description, site }`, where `text` is the whole file. Return a string, or `{ markdown, footer }`: only the `.md` copy ends with `footer`, and `llms-full.txt` and `get-page` leave it out. |

```ts [server/content.ts]
import { contentSource, defineContent } from 'vite-hub/content'
import { glob } from 'vite-hub/source'

export default defineContent({
  sources: {
    guides: contentSource(glob({ cwd: 'content', include: 'guides/*.md' }), {
      url: '/:id',
      seo: ({ data }) => ({ noindex: data.draft === true }),
    }),
  },
  seo: { site: 'https://example.com', llms: { title: 'Example' } },
})
```

### Write the copy yourself

A page can hold blocks that mean nothing outside the browser, such as a booking form, or a component that reads its words from the app, such as a `::phrases` table. Pass `markdown` to `documents()` or `singleton()` to write the copy that agents read:

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

const phrases = [['Hello', 'สวัสดี'], ['Thank you', 'ขอบคุณ']]
const phrasesTable = () => ['| Meaning | Thai |', '| --- | --- |', ...phrases.map(([meaning, thai]) => `| ${meaning} | ${thai} |`)].join('\n')

export default defineContent({
  workspace: 'site',
  collections: {
    guide: documents({
      path: 'guide/*.md',
      url: '/guide/:id',
      fields: { title: z.string(), description: z.string().optional() },
      markdown: ({ title, description, body }) => [
        `# ${title}`,
        description && `> ${description}`,
        body.replace(/^::phrases\n::$/m, phrasesTable()).replace(/^::booking-form\n::\n?/m, ''),
      ].filter(Boolean).join('\n\n'),
    }),
  },
  seo: { site: 'https://example.com', llms: { title: 'Trip guide' } },
})
```

The function gets `{ id, path, locale, data, body, title, description, site }` of the published document. `title` and `description` come from its `seo()` field, else from its fields. Return a string, or `{ markdown, footer }`: only the `.md` copy ends with `footer`, and `llms-full.txt` and `get-page` leave it out. Return `null` for a page without a copy. Content uses the result as it is, so make links absolute yourself if agents need them. The `.md` copy, the `Accept: text/markdown` answer, `llms-full.txt`, and the MCP `get-page` tool all use it. A Source takes the same function in `contentSource(input, { markdown })`, with the whole file as `text`.

To keep the copies and the llms files out of search results, such as for an unlisted site, set `llms: { headers: { 'x-robots-tag': 'noindex' } }`, and add the same header to the copies with [route rules](https://nuxt.com/docs/guide/concepts/rendering#route-rules): `routeRules: { '/raw/**': { headers: { 'x-robots-tag': 'noindex' } } }`.

A `site` with a path, such as `https://example.com/docs` for an app mounted there, keeps the path in every URL that these files and the MCP server write.

An HTML page that has a copy gets `Vary: Accept`, so a cache keeps the HTML and the Markdown apart, and a `Link: </blog/hello.md>; rel="alternate"; type="text/markdown"` header, so an agent finds the copy from the response alone. Every response at a URL with a copy varies on `Accept`, including JSON, assets, and redirects. URLs without copies keep their headers unless they return a 404. A copy has `Content-Location`, its `.md` URL, and an `ETag`, so a request with `If-None-Match` gets a `304` when the copy did not change. When a request asks for Markdown, with `.md` or with `Accept`, and no page answers it, the response is a `404` with a Markdown body. A `.md` URL that only an HTML page answers, such as the shell of a single-page app, gets the same `404`. The body names `/llms.txt` and the sitemaps, so an agent knows where to look next.

### App pages as Markdown

`seo: { markdown: { pages: true } }` gives a copy to the app pages that are not Content documents, such as a pricing page or a dashboard. A Markdown request for such a page renders the page inside the server, without a network hop, for the same request with its cookies and `Authorization` header. Content converts the HTML with [mdream](https://github.com/harlan-zw/mdream): it keeps the `<main>` part and leaves out navigation, footers, buttons, forms, scripts, and hidden elements. When the content has no heading first, the page `<title>` becomes the heading. A Content document keeps its exact copy.

```ts [server/content.ts]
import { defineContent } from 'vite-hub/content'

export default defineContent({
  seo: { site: 'https://example.com', markdown: { pages: true } },
})
```

- Only a `200` HTML page gets a copy. A page with `X-Robots-Tag: noindex` gets none. The copy keeps the page's `X-Robots-Tag` and its robots meta tag as `X-Robots-Tag`.
- A `404` page gets the Markdown 404. A redirect, such as to a sign-in page, or an error is the answer for the copy too.
- A copy of a page that the request's cookies or `Authorization` header can change has `Cache-Control: private, no-store`, so no shared cache gives it to another reader. The page's own `Set-Cookie` headers stay.
- The copy has `Link: <page>; rel="canonical"`, so search engines index the page and not the copy.

Off by default. [Docs sites](https://vitehub.dev/docs/docs-site/configure#agent-resources) turn it on. ViteHub renders the page with `serverFetch` from `nitro`. In another server, pass your own renderer: `defineContentMarkdownHandler(content, { render: request => app.fetch(request) })`.

Check the output from code:

```ts [server/utils/agent-check.ts]
import content from '../content'

export async function checkAgentFiles() {
  await content.llms()                           // llms.txt
  await content.llms({ file: 'llms-full.txt' })
  await content.llms({ file: 'llms-full.txt', locale: 'es' })
  await content.llms({ file: 'sitemap.md' })
  await content.markdown('/blog/hello.md')       // the copy, or null
  await content.hasMarkdown('/blog/hello.md')    // true when the copy exists
}
```

ViteHub generates these routes from `server/content.ts` like the sitemap, when `seo` sets `markdown` or `llms` to anything but literal `false`. The Markdown copies are middleware, because no route pattern matches a URL plus `.md`. The middleware loads when the server starts, so it can see a missing page, but it loads `server/content.ts` only on the first request that asks for Markdown or gets an HTML page. In another server, mount `defineContentLlmsHandler(content)` at the three paths and at `/:locale/llms-full.txt` and `defineContentMarkdownHandler(content)` as middleware.

## Console

When a collection has a `seo()` field, the [Console editor](https://vitehub.dev/docs/content/console) shows an **SEO** group below the document fields. It folds while empty, shows how many values are set, and opens when a value has an issue. It has:

- Title and description counters that turn amber past the recommended length.
- Placeholders that show the `contentHead()` fallback, such as the document title, summary, and URL.
- A search result preview, dimmed when the page is hidden from search engines.
- A 1.91:1 social card preview. A Blob image shows through the Blob serve route when it is on, else a placeholder.

<!-- 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)
- [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) (this page)
- [CLI](https://vitehub.dev/raw/docs/content/cli.md)
- [Translate with an Agent](https://vitehub.dev/raw/docs/content/translate-with-an-agent.md)

Next: [CLI](https://vitehub.dev/raw/docs/content/cli.md)

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