# Writing content

Standard Markdown, plus the handful of components docs actually need.

Source: https://bugstars-docs.pages.dev/writing-content/

---

## The file

A documentation page is an `.mdx` file under `src/content/docs/`, and its path is its URL: `src/content/docs/webhooks.mdx` is `/webhooks/`. Only `.mdx` files are loaded — a `.md` file there is silently ignored, with no build error. MDX is Markdown plus components, so everything you know about Markdown still applies.

## Frontmatter

Only `title` is required. `group` and `order` place the page in the sidebar; omit `group` and the page still builds and is searchable — it just doesn't appear in the nav.

| Key | Type | Default | Effect |
| --- | --- | --- | --- |
| `title` | string | — | Page heading, browser title, search result |
| `description` | string | — | The lede under the title, and the meta description |
| `group` | string | — | Sidebar group. No group means no sidebar entry |
| `order` | number | `0` | Position within the group |
| `keywords` | string\[\] | — | Meta keywords |
| `image` | string | — | Social share image |
| `noindex` | boolean | `false` | Keeps the page out of search engines and site search |
| `showTableOfContents` | boolean | `true` | On-this-page rail |
| `showFeedback` | boolean | `true` | The helpful vote at the foot of the page |
| `showCopyPage` | boolean | `true` | The [Copy page](/copy-page/) menu beside the title |
| `showPager` | boolean | `true` | Previous/next links |

The "Updated" date beside each page's title is not frontmatter — it is the file's last commit, read when the site builds. Edit a page and the date follows.

## Callouts

Four kinds. Use them for things a reader would otherwise learn the hard way.

<Alert variant="note" title="Note" text="Context that helps, but isn't required to succeed."/>

<Alert variant="tip" title="Tip" text="A shortcut once the reader knows the basics."/>

<Alert variant="warning" title="Warning" text="Something that will surprise them if they skip it."/>

<Alert variant="danger" title="Danger" text="Data loss, irreversible actions, breaking changes."/>

<CodeBlock language="mdx" filename="callout.mdx" showCopy={true}>

```
<Alert
  variant="warning"
  title="Rotating a key revokes the old one"
  text="Existing clients fail on the next request. Deploy the new key before rotating."
/>
```

</CodeBlock>

## Code blocks

`CodeBlock` takes the sample, its language, a `filename` for the header bar and a line range to highlight. The sample goes in a fence between the tags, so it keeps its indentation exactly; leave the fence bare and put the language on `CodeBlock`.

<CodeBlock language="mdx" filename="sample.mdx" showCopy={true}>

````
<CodeBlock language="json" filename="src/data/theme.json" highlight="3" showCopy={true}>

```
…
```

</CodeBlock>
````

</CodeBlock>

<CodeBlock language="json" filename="src/data/theme.json" highlight="3" showCopy={true}>

```
{
  "themeSelector": true,
  "defaultTheme": "dark"
}
```

</CodeBlock>

## Diffs

`CodeDiff` names its changed lines in `added`, `removed` and `highlight`, the same `"2"` or `"1,4-6"` form every code component uses. The code stays the literal sample, so it keeps its own language colors instead of going flat the way a `diff` fence does, and the copy button hands back something that runs.

<CodeDiff language="json" filename="src/data/theme.json" added="4" removed="3" highlight="6" showCopy={true}>

```
{
  "themeSelector": true,
  "defaultTheme": "light",
  "defaultTheme": "dark",
  "theme": {
    "accentLight": "#0f766e"
  }
}
```

</CodeDiff>

Line numbers count the sample's own lines, so they need a look after an edit that adds or removes one.

## File trees

`FileTree` draws the connectors from an indented list of paths, so the tree stays editable as text. Any consistent indent unit works, and it takes the same `added`, `removed` and `highlight` line numbers as a diff — counting the rendered rows, so a blank line in the list doesn't shift them.

<FileTree title="Project structure" added="4" showCopy={true}>

```
src/
  components/
    Button.astro
    Callout.astro
  styles/
    base.css
astro.config.mjs
```

</FileTree>

## Language tabs

Use `CodeTabs` for one sample in several languages. The reader's choice is remembered site-wide, so a Python developer stays in Python across every page.

<CodeTabs showCopy={true}>
<CodeTab label="cURL" language="bash">

```
curl https://api.acme.com/v1/invoices \
  -H "Authorization: Bearer $ACME_KEY" \
  -d customer=cus_8Kq2 \
  -d amount=4900
```

</CodeTab>
<CodeTab label="Node" language="js">

```
import { Acme } from '@acme/sdk'

const acme = new Acme(process.env.ACME_KEY)

const invoice = await acme.invoices.create({
  customer: 'cus_8Kq2',
  amount: 4900,
})
```

</CodeTab>
<CodeTab label="Python" language="python">

```
from acme import Acme

acme = Acme(os.environ['ACME_KEY'])

invoice = acme.invoices.create(
    customer='cus_8Kq2',
    amount=4900,
)
```

</CodeTab>
</CodeTabs>

## Code annotations

Notes sit under the block rather than in comments, so the snippet stays copy-paste clean. Each note names the line it marks.

<CodeAnnotations language="json" filename="src/data/header.json" notes={[{ line: 2, text: "Builds the search index at compile time and ships it with the site — no search service, no API key." }, { line: 4, text: "Links beside the brand. Add, remove and reorder them on the page in CloudCannon's Visual Editor." }]} showCopy={true}>

```
{
  "search": true,
  "themeToggle": true,
  "topbarLinks": [
    { "name": "GitHub", "path": "https://github.com/acme/docs" }
  ]
}
```

</CodeAnnotations>

## Tables

Markdown tables get a bordered panel and horizontal scroll on narrow screens.

| Event | Retries | Payload |
| --- | --- | --- |
| `invoice.paid` | 5 | Invoice object |
| `user.created` | 3 | User object |
| `plan.changed` | 3 | Subscription delta |

## Footnotes

Put a marker in the sentence and the note anywhere in the file. Notes collect at the foot of the page in marker order, each with a link back to where it was cited.[^1] Use them for an aside that would break the flow of a sentence, such as a source or an edge case.[^2]

<CodeBlock language="mdx" filename="footnote.mdx" showCopy={true}>

```
Retries back off exponentially.[^1]

[^1]: 1s, 2s, 4s, 8s, then 16s, with up to 20% jitter.
```

</CodeBlock>

[^1]:
    Use a number as the id. The Content Editor only recognizes numbered footnotes, and saves any other id as plain text.

[^2]:
    Footnotes survive the print layout, so a saved PDF keeps its sources.

## Cross-links

Link by URL — `[Configuration](/configuration/)`. `npm run lint:links` fails `npm run check` on an internal link that points at no page, so a renamed page can't quietly rot. It also warns about orphan pages — a page with no sidebar `group` that no other page links to, which readers can only find through search.
