# Directory

<StatusBadge status="available" /> `format: directory` turns a :term[story]{id=story} into a
**directory**: an "awesome" list read as it is, each `## heading` a category, each item an entry
(`- [Name](url) - summary`). The same file is shown as cards, a list or a table, filtered by
category, tag, city and country in the URL (`?category=studios&city=Paris`, shareable), and, with
`pages: true`, a page per entry.

The example is `directory-links` (a raw awesome list, no braces). The
[glossary](/formats/glossary/overview) shares the same model of entries.

## A minimal directory

```md title="places.md"
---
title: Lorem Places
format: directory
lang: en
entries: places # links | places | organizations
view: cards # cards | list | table
pages: false
---

--- id=studios

## Studios

- [Lorem Studio](https://example.com) - Dolor sit amet. {tags=design,print street="1 Lorem Street" city=Paris postcode=75000 country=FR geo=48.8566,2.3522}
- [Ipsum Lab](https://example.org) - Consectetur adipiscing. {tags=video city=Lyon country=FR}

--- id=venues

## Venues

- [Dolor Hall](https://example.net) - Sed do eiusmod. {tags=music city=Paris country=FR sponsored}

:::entry{id=dolor-hall}
The long record of an entry, in Markdown, when one line is not enough: opening hours, access.
:::
```

| In the `{…}` of an entry                                 | What it is                                                    |
| -------------------------------------------------------- | ------------------------------------------------------------- |
| `id`                                                     | default: the slug of the name                                 |
| `tags`                                                   | comma-separated                                               |
| `email`, `phone`, `image`                                | contact; `image` is a local file, never fetched from the site |
| `street`, `city`, `postcode`, `region`, `country`, `geo` | the place: `country` in ISO 3166 (`FR`), `geo` as `lat,lng`   |
| `address`                                                | free text, shown as it is, never parsed                       |
| `sponsored`                                              | a visible mention and `rel="sponsored"`                       |

A `:::entry{id=…}` block after the items holds the long record of the entry with that id; an id that
is not an entry of the section is an error. A link is `http:` or `https:` only. Country names are
shown in the page's language (`Intl.DisplayNames`).

## Settings

In the front matter, or for every directory of a folder in the `directory:` section of
`recit.config.ts` (the front matter wins).

| Setting   | Default             | What it does                                                                             |
| --------- | ------------------- | ---------------------------------------------------------------------------------------- |
| `entries` | `links`             | what one entry is: `links`, `places` or `organizations`                                  |
| `view`    | `cards`             | the view shown first: `cards`, `list`, `table` or `map` (the map needs the maps package) |
| `pages`   | `false`             | one page per entry                                                                       |
| `facets`  | `[category, tags]`  | the filters offered, in order, in the URL: `category`, `tags`, `city`, `country`         |
| `strict`  | `false`             | every entry writes its `{id=…}`; an entry without one is an error                        |
| `pdf`     | A4 portrait, a list | `recit export --to pdf`: `view` (`list`, `table` or `cards`), the page box               |

With `strict: true` (front matter, or `directory: { strict: true }` in `recit.config`), every entry
writes its id. Each entry without one is an error of `recit validate` and of the build, at its line:
in the directory above, under `directory: { strict: true }`, `Lorem Studio` (`places.md:14`),
`Ipsum Lab` (`✖ places.md:15 — entry "Ipsum Lab" has no id (strict)`) and `Dolor Hall`
(`places.md:21`). A `:::entry{id=…}` block does not count: the id goes in the `{…}` of the item,
`{id=ipsum-lab tags=video city=Lyon country=FR}`. A companion file that completes an entry (the
`linkStatus` of `recit validate --links`) leaves the rule as it is. This is not `--strict` of
`recit validate --links`, which turns broken links into errors.

```ts title="recit.config.ts"
import { defineConfig } from "recit/config";

export default defineConfig({
  directory: {
    entries: "places",
    view: "table",
    facets: ["category", "city", "country"],
    strict: true,
  },
});
```

## The map view

On the page served by `recit dev` or built by `recit build`, when at least one entry has coordinates
(`geo=lat,lon`, or a `place` whose entry in the places directory has them), **Map** appears
alongside **Cards**, **List** and **Table** and marks every entry that matches the active filters on
the country base map of `@recit/geo` (static SVG, no external tiles). Set `view: map` in the front
matter or under `directory:` in `recit.config.ts` to open on the map first; when no entry has a
geolocated place, the option is not offered and `view: map` falls back to **Cards**. When the
filters leave no entry with coordinates, the map view says so instead of drawing an empty map. A
glossary, or a directory without coordinates, does not need `@recit/geo` and its page does not carry
the map.

```md title="places.md"
---
title: Lorem Places
format: directory
entries: places
view: map
---

## Studios

- [Lorem Studio](https://example.com) - Dolor sit amet. {tags=design,print street="1 Lorem Street" city=Paris postcode=75000 country=FR geo=48.8566,2.3522}
```

A React component that embeds `Directory` (`@recit/directory/components`) can provide its map
through the `renderMap(markers)` prop (`view: "map"` falls back to cards without it);
`entryMarkers(entries)` from `@recit/directory` returns the [`::map`](/documentation/writing/maps)
`marker` layers for the geolocated entries.

## Proposals through a form

Visitors can propose an entry without writing Markdown; nothing is published before you read it.
`entryProposalForm` from `@recit/directory` writes the [`:::form`](/documentation/writing/forms)
block, its fields named like the columns of a directory table (`name`, `url`, `summary`, `category`,
`tags`, `email`, `city`, `country`), in English or French (`lang`). Pass the categories you offer,
your endpoint (`submit`, `mock` by default) and your privacy page (`privacy`); without one, the form
asks for consent.

```ts
import { entryProposalForm } from "@recit/directory";

const markdown = entryProposalForm({
  lang: "fr",
  categories: ["Studios", "Venues"],
  submit: "/api/forms",
  privacy: "/privacy",
});
```

Where the submission arrives (`onSubmit` of `createFormHandler` in `@recit/form/server`),
`submissionToEntry(data, { categories })` checks it against the entry schema: an address that is not
`http:` or `https:`, an invalid email or a category you did not offer is refused with its issues
(`ok: false`), and a visitor never chooses the `id` (it comes from the name) nor `sponsored`.
`proposalToMarkdown(entry)` then writes the entry under its category, the Markdown you read and
paste into the directory.

```ts
import { proposalToMarkdown, submissionToEntry } from "@recit/directory";

const proposal = submissionToEntry(submission.data, {
  categories: ["Studios", "Venues"],
});
if (proposal.ok) await saveForReview(proposalToMarkdown(proposal.entry));
```

## Structured data

The page that `recit build` writes carries the directory's schema.org data in its head: an
`ItemList` of its entries, in the order of the page. An entry with an address or a location is a
`Place`, written as a calendar writes the place of an event (`location=@id` gives the same node),
with its telephone and e-mail; any other entry is a `Thing`, with its name, summary, link and image.
`entriesJsonLd({ format: "directory", directory })` of `@recit/directory` gives the same document to
a site; with `pageUrl`, an entry without its own link gets its anchor on the page as `url`.

## Commands

| Command                                                               | What it does                                                                                                                                |
| --------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
| `recit validate places.md --links`                                    | checks the links (cache `.recit/cache/links.json`, `Retry-After`, a redirection to another domain); warnings, errors with `--strict`        |
| `recit geocode places.md`                                             | asks the position of each place without `geo`, one request a second, and writes it into the companion ([below](#positions-from-an-address)) |
| `recit convert places.csv --to directory --columns name=Nom,url=Site` | a table to a directory; an unmapped column is left aside with a warning, never guessed                                                      |
| `recit convert places.md --to csv`                                    | the directory as a table, a closed set of columns                                                                                           |
| `recit convert places.md --to deck`                                   | one slide per entry, or `--per section`                                                                                                     |
| `recit convert places.md --to webstory`                               | one card per entry, its link as the call to action, or `--per section`                                                                      |
| `recit convert places.md`                                             | the JSON twin, and back from `places.json`                                                                                                  |
| `recit dev places.md`, `recit build places.md`                        | the directory as a page, served while you write or built to static files                                                                    |
| `recit export places.md --to pdf -o places.pdf`                       | every entry, unfiltered, as a list, A4 portrait with its page numbers                                                                       |

The PDF prints every entry, with no filter and no map: `pdf: { view: "table" }` (front matter, or
`directory: { pdf: … }` in `recit.config`) prints them as a table, `cards` as cards. The `pdf` key
takes the [PDF options](/documentation/configuration/recit-config#pdf-options) of every paginated
format (`page`, `header`, `footer`, `colorMode`, `output`…); the file lands next to the story unless
`-o` or `pdf.output` names it, and is listed in `exports.json`.

### Positions from an address

`recit geocode places.md` is the only geocoding of Récit, for directories and maps alike. It runs on
your machine when you ask, never at build or render time. For each entry with a place and no `geo`,
it asks a [Nominatim](https://nominatim.org) service for the street, postcode, city, region and
country (or the free `address` when there is none of the first three), and writes the answer into
the `kind: "sidecar"` companion `places.json`, as the entry's `place` with its `geo`. The Markdown
is never rewritten: read the companion, and write `geo=lat,lon` in the entry's braces when you
prefer a position of your own, which the command then leaves alone.

- **The rules of the public Nominatim hold for every service**: one request a second at most, an
  identifiable User-Agent, answers kept for 90 days in `.recit/cache/geocode.json` (`--max-age`),
  and no request for an entry whose companion already holds a position for the same address. Change
  an address in the Markdown and run the command again: that entry alone is asked again.
- **The service is yours to choose**: `--endpoint` points at your own Nominatim or a hosted one
  (LocationIQ and others speak the same API); `--key-env NAME` reads its key from the environment,
  never from a file; `--email` gives the public Nominatim a contact for more than a few requests.
- **`--dry-run`** lists what would be asked and sends nothing. An address not found is a warning
  that names the entry, an error with `--strict`.
- **The credit**: positions from the public Nominatim are OpenStreetMap data, under the ODbL. The
  command prints the line to show on the published site: « Data © OpenStreetMap contributors, ODbL
  1.0 ».

## Bridges

| Where                                                              | What it gives                                                              |
| ------------------------------------------------------------------ | -------------------------------------------------------------------------- |
| `::directory{src=./places.md category=studios limit=6}` on a slide | a few entries as cards                                                     |
| `data: { places: ./places.md }` in a report                        | one row per entry: `:value{data=places agg=count where="section=studios"}` |
| a calendar with `places: ./places.md`                              | `location=@dolor-hall` takes the entry's name and place                    |
| MCP `search_directory`                                             | entries filtered by text, category, tag, city or country                   |

## The JSON twin

A `kind: "story"` file (`https://recit.dev/schema/v1/directory.json`, `format: "directory"`,
`version: 1`) next to the `.md` holds the same directory under the story envelope (`syntax`,
`preamble`, `meta`, `data`, `settings` — see
[Scenes › In the JSON twin](/documentation/writing/scenes#in-the-json-twin)) and `scenes`, while a
`kind: "sidecar"` companion (`places.json`) completes scenes and entries by `id`.

| Key              | Type / values                                 | Effect                                                                                                                                   |
| ---------------- | --------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
| `scenes`         | `object[]`                                    | Required in `kind: "story"`. Sections of the directory, in order (`---` separators in Markdown).                                         |
| `scenes.id`      | `string` (non-empty)                          | Required. Stable section identifier across languages (`--- id=…` in Markdown; [Scenes](/documentation/writing/scenes#in-the-json-twin)). |
| `scenes.title`   | `string` or `Record<string, string>`          | Optional section heading (`# Heading` at the start of the section).                                                                      |
| `scenes.body`    | `string` or `Record<string, string>`          | Optional Markdown or MDX prose of the section before its entries ([Scenes](/documentation/writing/scenes#in-the-json-twin)).             |
| `scenes.notes`   | `string` or `Record<string, string>`          | Optional author notes in Markdown (`:::notes`; [Scenes](/documentation/writing/scenes#in-the-json-twin)).                                |
| `scenes.attrs`   | `Record<string, string \| number \| boolean>` | Optional separator attributes (`--- key=value`) other than `id` ([Scenes](/documentation/writing/scenes#in-the-json-twin)).              |
| `scenes.entries` | `object[]`                                    | Optional list of directory entries in this section.                                                                                      |

Each object in `scenes.entries` describes one listed site, place or organization (`entries.id` and
`entries.name` are required in `kind: "story"`):

| Key                  | Type / values                                             | Effect                                                                                                                                                               |
| -------------------- | --------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `entries.id`         | `string` (`^[a-z0-9][\w-]*$`)                             | Required. Stable entry id (anchor, sidecar key and `@id` location reference); derived from `entries.name` in Markdown unless `{id=…}` is set (required in `strict`). |
| `entries.name`       | `string` or `Record<string, string>`                      | Required. Display name of the entry (`[Name](url)` or item title before `-` in Markdown).                                                                            |
| `entries.aliases`    | `string[]` (non-empty) or `Record<string, string[]>`      | Alternative names (`{aliases=a,b}` in Markdown); claiming a name or alias already used by another entry is an error.                                                 |
| `entries.summary`    | `string` or `Record<string, string>`                      | One-line Markdown summary written after `-` on the list item.                                                                                                        |
| `entries.body`       | `string` or `Record<string, string>`                      | Long Markdown record of the entry (`:::entry{id=…}` block in Markdown).                                                                                              |
| `entries.category`   | `string` (non-empty)                                      | Category of the entry (`## Heading` above it or `{category=…}`), used for grouping and the `category` facet.                                                         |
| `entries.url`        | `string` (`http:` or `https:` URI)                        | External link of `[Name](url)`; omitting it warns (`directory-link-url`) when `entries` is `"links"`.                                                                |
| `entries.tags`       | `string[]` (non-empty)                                    | Tags (`{tags=a,b}` in Markdown), used by the `tags` facet (`?tag=…`) and text search.                                                                                |
| `entries.see`        | `string[]` (non-empty)                                    | Ids of related entries in the same directory (`{see=id,id}` in Markdown; an unknown id is an error).                                                                 |
| `entries.email`      | `string` (email)                                          | Contact email address (`{email=…}` in Markdown).                                                                                                                     |
| `entries.phone`      | `string` (non-empty)                                      | Contact phone number (`{phone=…}` in Markdown).                                                                                                                      |
| `entries.place`      | `object`                                                  | Physical location of the entry (its fields other than `place.name` sit flat in `{…}` in Markdown), also resolved by `location=@id` in a calendar.                    |
| `place.name`         | `string` or `Record<string, string>`                      | Optional localized place name; falls back to `entries.name` when referenced as `@id`.                                                                                |
| `place.address`      | `string`                                                  | Free-text address (`{address="…"}`), shown as it is and never parsed into structured postal fields.                                                                  |
| `place.street`       | `string`                                                  | Street address (`{street="…"}`).                                                                                                                                     |
| `place.city`         | `string`                                                  | City or locality (`{city=…}`), used by the `city` facet.                                                                                                             |
| `place.postcode`     | `string`                                                  | Postal code (`{postcode=…}`).                                                                                                                                        |
| `place.region`       | `string`                                                  | Region, state or administrative area (`{region=…}`).                                                                                                                 |
| `place.country`      | `string` (`^[A-Z]{2}$`)                                   | ISO 3166-1 alpha-2 country code (`{country=FR}`), formatted in the page's language (`Intl.DisplayNames`) and used by the `country` facet.                            |
| `place.geo`          | `[number, number]` (`[-90, 90]`, `[-180, 180]`)           | `[latitude, longitude]` coordinates (`{geo=lat,lng}` in Markdown).                                                                                                   |
| `entries.sameAs`     | `string[]` (`http:` or `https:` URIs)                     | Additional external URLs of the entry (`{sameAs=url,url}` in Markdown).                                                                                              |
| `entries.image`      | `string` (non-empty)                                      | Local image path (`{image=…}` in Markdown), never fetched from the listed site.                                                                                      |
| `entries.source`     | `{ url, license? }`                                       | Provenance of the entry (`{source=… license=…}` in Markdown; `license` without `source` is an error).                                                                |
| `source.url`         | `string` (`http:` or `https:` URI)                        | Required when `entries.source` is set. Source URL (`{source=…}` in Markdown).                                                                                        |
| `source.license`     | `string` (non-empty)                                      | Optional license identifier or name (`{license=…}` in Markdown).                                                                                                     |
| `entries.sponsored`  | `boolean`                                                 | Shows a visible "Sponsored" mention and adds `rel="sponsored"` on the link (`{sponsored}` in Markdown).                                                              |
| `entries.linkStatus` | `"ok"` \| `"redirected"` \| `"broken"` \| `"unreachable"` | Result of `recit validate --links`, written in the `kind: "sidecar"` companion (never in Markdown); `"redirected"`, `"broken"` and `"unreachable"` show "to check".  |
| `entries.checkedAt`  | `string` (ISO 8601 date-time with offset)                 | Timestamp of the last link check, written in the companion by `recit validate --links`.                                                                              |
| `entries.finalUrl`   | `string` (`http:` or `https:` URI)                        | Final URL reached after redirects during `recit validate --links`, written in the companion.                                                                         |
