# Data in site pages

A site built on `@recit/site` with `recit/config` (`@recit/site-stories`) can use the four data
directives of `@recit/data` — `:value`, `:::kpi`, `::chart` and `::table` — directly inside its
`pages/*.md` and `pages/*.mdx` files, with the exact same syntax and
[attributes](/formats/report/data) as a report or a deck.

## Setup

Add `@recit/data` to the site's `dependencies` (and `@recit/geo` when pages draw `type=choropleth`
or `type=points` maps):

```json title="package.json"
{
  "dependencies": {
    "@recit/data": "^0.1.0",
    "@recit/geo": "^0.1.0",
    "@recit/site-stories": "^1.0.0",
    "recit": "^1.0.0"
  }
}
```

No extra import is needed in `recit.config.ts`:

- Every figure, number and table is computed **at build time** in Node as static HTML and SVG. Raw
  source paths and inline rows are stripped from the page's client front matter.
- `@recit/data/styles.css` (and `@recit/geo/styles.css` on pages with maps) is imported only by the
  lazy route chunk of pages that render data directives, never in `entry.client`.
- `@recit/data/client` (keyboard arrow navigation across marks and hover/focus tooltips) loads on
  demand after hydration only on pages that render a chart figure.
- A page without `data:` in its front matter does not change by a single byte.
- A missing data file or an invalid directive attribute stops the build with the page's file path
  and 1-based line number (`✖ pages/metrics.mdx:5 — source "sales": cannot read ./missing.csv`).

## Declare `data:` in front matter

List CSV, JSON or YAML tables, inline `rows`, or precomputed
[`chart.json`](/formats/report/data#a-ready-chart) files relative to the page (a CSV file may use
`,` or `;` as its separator, detected from its header line; a header name that is empty or repeated
is an error):

```yaml title="pages/metrics.mdx"
---
title: Metrics
data:
  sales: ./data-in-pages/sales.csv
  schedule: { chart: ./data-in-pages/schedule.json }
  spots: { chart: ./data-in-pages/spots.json }
---
```

An inline `rows` entry (or a plugin `source:` entry) can also declare `meta` provenance (`title`,
`url`, `publisher`, `license`, `modified`). When `::chart` has no `source=` attribute, it builds its
`Source:` credit line from `publisher`, `title` and `(license)`:

```yaml
data:
  targets:
    rows:
      - { month: 2026-01, revenue: 120 }
      - { month: 2026-02, revenue: 150 }
    meta:
      title: Dolor sit amet
      publisher: Lorem Ipsum Institute
      license: CC-BY-4.0
      modified: 2026-11-01
      url: https://example.org/lorem
```

## Inline `:value` and `:::kpi`

Across the five months in `./data-in-pages/sales.csv`, total revenue reaches :value{data=sales field=revenue agg=sum} units across :value{data=sales field=orders agg=sum} orders:

:::kpi{cols=3}

- :value{data=sales field=revenue agg=sum}
  Total revenue
  Five months, Lorem region
- :value{data=sales field=revenue agg=max}
  Peak month
  March 2026
- :value{data=sales field=orders agg=sum}
  Orders
  Cumulative volume

:::

## Bar `::chart` with `highlight=` and `marks=`

`highlight=` puts one or more categories or series forward (outlined in the text ink while the other
bars fade), and `marks=` draws dashed reference lines across `x` or `y`. Under every chart, the «
Data » disclosure (`« Données »` when the site's `metadata.lang` or the page's `lang` is `fr`)
exposes the plotted table:

::chart{data=sales type=bar x=month y=revenue highlight="2026-03" marks="y=150|Target" title="Lorem revenue by month" subtitle="Units sold per month, March highlighted" xLabel="Month" yLabel="Revenue" source="Lorem dataset, 2026"}

## Heatmap with `rowGroups` and hatched `null`

Ready `chart.json` files support grouped rows (`rowGroups`) and missing cells (`null`, drawn with a
45° « No data » hatch in the grid and in the scale legend):

::chart{data=schedule}

## Points map (`type=points`)

When `@recit/geo` is installed, `::chart` also renders `type=choropleth` and `type=points` in
longitude and latitude, with sized groups, colour `roles`, connecting `lines` and `highlight`:

::chart{data=spots}

## Formatted `::table`

`::table` renders sorted, filtered rows from any declared source:

::table{data=sales columns="month,region,revenue,orders" sort=-revenue limit=4 caption="Top four months by revenue"}
