# Build a docs site

```sh
charon build docs -o site
```

That reads every `.md` file under `docs/` and writes a finished site to
`site/`. Every page gets:

- a sidebar, previous and next links, and an "On this page" list
- an anchor link on every `h2` and `h3`
- links between pages by file path, `[Install](install.md)`, or by wikilink, `[[Install]]`
- a Markdown copy at its URL plus `.md`, behind a "View as Markdown" button
- search over every section, run in the browser
- a "Last updated" date from git
- a social card image, if you [ask for one](social-cards.md)

The site also gets `llms.txt`, `llms-full.txt` and, with a site URL,
`sitemap.xml`. A link to a missing page or heading fails the build.

This site is one, built by `charon build` from a folder of Markdown.

## Two ways to build

- **`charon build`** writes a static site in charon's default theme. Nothing
  else to install.
- **The [Vite plugin](vite.md)** renders the pages inside your own Vite site,
  with your template, CSS and scripts.

Both run the same core, so pages read the same either way.

## Serve it

```sh
charon build docs -o site --name "Acme Docs" --site-url https://acme.dev
charon build docs -o public --base /docs
```

`-o` is the web root: with `--base /docs` the pages land in `public/docs/`.
Any static host that maps `/guide` to `/guide/index.html` serves it.

A rebuild deletes what the last build wrote and this one did not, such as a
removed page. It reads that list from `_charon/files.json` and leaves every
other file in the output folder alone.

## charon.json

Put options in `docs/charon.json` instead of flags. Paths in it are relative to
the file:

```json
{
  "name": "Acme Docs",
  "siteUrl": "https://acme.dev",
  "sections": [
    { "title": "Start", "pages": ["", "install"] },
    { "title": "Guides", "pages": ["guides/deploy"] }
  ],
  "links": { "app:/": "https://app.acme.dev/" }
}
```

| Flag             | Key        | Default                |
| ---------------- | ---------- | ---------------------- |
| `-o, --out`      | `out`      | `site`                 |
| `--name`         | `name`     | `Docs`                 |
| `--base`         | `base`     | none                   |
| `--site-url`     | `siteUrl`  | none                   |
| `--template`     | `template` | charon's own           |
| `--assets`       | `assets`   | `<dir>/assets`         |
| `--diagram-font` | `diagrams` | pele's default         |
| `--og`           | `og`       | no cards               |
| `--og-font`      | `og.fonts` | JetBrains Mono         |
| `--config`       |            | `<dir>/charon.json`    |
|                  | `sections` | one per folder         |
|                  | `links`    | `{}`                   |
|                  | `lang`     | `en`                   |
|                  | `labels`   | English                |
|                  | `contents` | `{ "minHeadings": 3 }` |

`--diagram-font Inter` is `"diagrams": { "fontFamily": "Inter" }` in the file.

- `sections` groups the sidebar and sets the order of previous and next. See
  [Write pages](pages.md#sections).
- `links` swaps a link prefix for another, so `[Open the app](app:/settings)`
  points at `https://app.acme.dev/settings`.
- `contents.minHeadings` is how many `h2`s a page needs before it gets an "On
  this page" list.
- `lang` and `labels` set the language; see [Labels and styles](labels.md).

## What it writes

| Path                              | Holds                          |
| --------------------------------- | ------------------------------ |
| `index.html`, `<page>/index.html` | each page                      |
| `index.md`, `<page>.md`           | each page's Markdown copy      |
| `search-index.json`               | the search index               |
| `llms.txt`, `llms-full.txt`       | page lists for language models |
| `sitemap.xml`                     | every page, with a site URL    |
| `<page>/og.png`                   | social cards, with `og`        |
| `assets/`                         | the assets folder, as is       |
| `_charon/`                        | the theme's CSS and script     |

Pages with math load KaTeX's CSS from jsDelivr.
