# Routing

Velora decides every content address. Editors set the patterns in Velora (an article can live at `/{slug}`, `/{category}/{slug}`, or a category's own pattern), rename things, and move them. Velora records a redirect from each old address. Your front end follows Velora, so links in article bodies, the sitemap and redirects always agree.

Two rules cover it:

1. **Serve every content path through `/resolve`.** One catch-all route in your front end asks Velora what lives at the path.
2. **Never build a URL.** Every answer carries a `path` (an article, a section, a writer, an entity, a nav item's `url`). Use it as the link, as it is.

## Resolve a path

```bash
curl -H "Authorization: Bearer $VELORA_READ_KEY" \
  "https://delivery.velora.build/$SITE_ID/resolve?path=/racing/tour-stage-one"
```

The answer's `kind` says what to do:

| `kind` | Do this |
| --- | --- |
| `article` | Render the article. It is in `article`, and `slug` is what `/articles/{slug}` takes. |
| `page` | Render the static page in `page` (`/pages/{slug}`). |
| `category` | Render the section listing in `category` (`/categories/{slug}`). |
| `entity_type` | Render the index of an entity type, such as `/riders`, from `entity_type` (`/entities/{slug}`). |
| `entity` | Render one entity, such as `/riders/tom-pidcock`, from `entity`. `type_slug` and `slug` are what `/entities/{type_slug}/{slug}` takes. |
| `redirect` | Answer a permanent redirect (308) to `to`. Velora has already collapsed a chain of moves into one hop. `to` can be another site entirely. |
| `not_found` | Answer 404. |

`/resolve` returns the content with the answer, so one call renders the page. A listing's content is its first page; pass `page` and `limit` for others. The `slug` fields let you call the content's own route instead if you prefer.

When a path holds content and a redirect, the content wins.

Paths are matched as your front end received them. Encode each segment (`encodeURIComponent` per segment) and pass the whole path, with its leading `/`, as `path`.

## Later pages of a listing

Sections, entity types, entities and writers list articles in pages. Give later pages a path, not a query string, so every page can be cached whole and nothing depends on `?page=`:

- Use `{listing}/page/{n}`, for example `/racing/page/2`.
- When a path resolves to `not_found` and ends in `/page/{n}`, resolve the part before it with `page=n`. Resolve the full path first, so content whose address happens to end that way still renders.
- Redirect an old `?page=2` link to the path form with a 308 if your site ever used one.

Each listing answer carries `page`, `pages` and `total`. Page numbers run to 500. To walk further back, use the [cursor](https://developers.velora.build/content.md#paging).

## Writers

Writers have pages at `/author/{slug}`, with the index at `/authors`. `/resolve` does not return writers: read `/authors/{slug}` for one writer's page and `/authors` for the index. When `/authors/{slug}` answers 404, resolve the path anyway: a renamed writer's old address answers `redirect`. Writers still come with a `path`; link to that.

## Addresses kept for your front end

Your front end serves some paths itself: search, the preview route, a writers index, your feed. Velora must never give content one of those addresses. Tell it which in Velora: **Publication**, the **Article addresses** section, **Kept for your front end**. Nothing in the publication is given a kept path, or anything under it. A save that would put content there is refused.

Velora always keeps these, on every site:

```
/api  /author  /markdown  /feed.xml  /sitemap.xml  /news-sitemap.xml  /llms.txt  /robots.txt
```

Each site also starts with `/authors`, `/search` and `/preview` kept. Edit that list to match the routes you build. It holds up to 50 paths.

Add a path to the list **before** you deploy a route on it ([Deploy order](https://developers.velora.build/deploy.md)). A redirect that would lead into a kept path stops there, so your route serves it.

## Markdown copies

Serve each article as markdown at its address plus `.md` (`/racing/tour-stage-one.md`), for AI agents and anyone who wants the text alone:

1. Strip `.md` and resolve the rest.
2. For `redirect`, answer 308 to `to` plus `.md` when `to` is a path on your site; to `to` as it is otherwise.
3. For `article`, read `/articles/{slug}?format=markdown`. The answer's `markdown` field is the body as markdown. Add the title, byline and date above it.
4. Links in the body are site-relative (`/racing/other-story`). Make them absolute with your site's origin, so the copy works on its own.
5. Answer with `Content-Type: text/markdown; charset=utf-8` and a `Link: <{origin}{seo.canonical_path}>; rel="canonical"` header pointing at the article page.

Velora's own [`/llms.txt`](https://developers.velora.build/feeds.md#llmstxt) links each article to this copy.
