# Table of contents and series

Every deck has a table of contents, with nothing to write: it is computed from the slides. Write a
little more and it becomes the tree you want. On a site, decks of one sidebar category become a
series, and a slide can link to a slide of another deck.

<StoryEmbed slug="course" slide={3} />

## Computed, never required

Without any option:

- **a label** is the first heading of a slide (`#`, `##`); a slide without a heading has no entry
  and falls under the one before it;
- **a section** starts at every `layout=section` slide, and the slides after it fall under it until
  the next section;
- a deck without a section slide is a flat list of its slides.

**M**, or the Contents button of the toolbar, opens the drawer: the tree of sections and slides,
each section folded or open with the slides it covers (`5–12`), the current slide marked. The arrows
walk the tree, Enter goes to the slide, Escape closes. On a phone, the drawer is a sheet rising from
the bottom. The presenter console has the same button.

## Short labels and sections

The options of a slide are the ones of a page of docs:

```md title="slides.md"
--- layout=section

# 1. Lorem notatio

--- sidebar_label="Definitio brevis"

# Definitio, with a long title

--- sidebar=false

# A slide left out of the contents

--- section="Quaestiones finales"

# Quaestiones
```

| Option          | Effect                                                                               |
| --------------- | ------------------------------------------------------------------------------------ |
| `sidebar_label` | the slide's label in the contents, the overview and the crumbs, instead of its title |
| `sidebar=false` | no entry for the slide; it falls under the entry before it                           |
| `section`       | a section starts at this slide, named by the text, without a `layout=section` slide  |

In the JSON twin they are typed fields of the scene: `"sidebar": false`,
`"sidebar": { "label": "Definitio brevis" }` and `"section": "Quaestiones finales"`. A slide has no
`order`: the deck's order is its order.

## Depth, numbers, or none

```md title="slides.md"
---
title: Lorem Ipsum Course
toc:
  depth: 1 # 1: the sections alone; 2: the sections and their slides (default)
  numbered: true # 1, 1.1, 1.2…
---
```

`toc: false` removes the Contents drawer, its button and its key, and leaves the sections of the
progress bar. `deck.toc` in `recit.config.ts` sets it for every deck; a deck's `toc:` wins.
`controls.overview: false` removes the drawer as well as the overview.

## The contents in a slide

`:::toc` writes the table of contents into a slide, as links to the slides (an agenda):

```md title="slides.md"
---

# Agenda

:::toc{depth=1}
:::
```

In an MDX deck, `<Toc />` and `<Toc depth={1} />` write the same list.

## A series of decks

On a site, the decks of one category of the sidebar are a series, in the sidebar's order:

```ts title="recit.config.ts"
export default defineConfig({
  navigation: [
    {
      type: "category",
      label: "Lorem Ipsum",
      items: [
        { type: "link", label: "Lorem origins", to: "/stories/origins" },
        { type: "link", label: "Dolor sit amet", to: "/stories/dolor" },
        { type: "link", label: "Ipsum horizons", to: "/stories/horizons" },
      ],
    },
  ],
});
```

- the foot of the Contents drawer names the series, says « Part 2 of 3 » and links to the decks
  before and after this one;
- after the last slide, a card leads to the next deck;
- on the page of a deck, the sidebar lists its sections, each a link to its first slide.

A category with one deck is no series, and a deck alone (`recit build`) has none.
`controls.series: false`, in the deck's `controls:` or in `deck.controls`, hides the foot and the
card.

## Grouping decks by theme

While a series orders decks meant to be read one after another, `publish.groups` and `group` on
`publish.entries` arrange published decks by theme in the sidebar and in `<StoryGallery />`:

```ts title="recit.config.ts"
export default defineConfig({
  publish: {
    groups: [
      { id: "foundations", label: { en: "Lorem foundations", fr: "Fondations lorem" }, icon: "layers", order: 1 },
      { id: "deep-dives", label: "Ipsum deep dives", icon: "compass", order: 2 },
    ],
    entries: [
      { slug: "overview", file: "./decks/overview.md" },
      { slug: "origins", file: "./decks/origins.md", group: "foundations" },
      { slug: "dolor", file: "./decks/dolor.md", group: "deep-dives" },
    ],
  },
});
```

- **In the sidebar** of a deck's page: decks without a `group` come first at the top level, followed
  by one collapsible section per group (open by default, with its localized `label` and its `icon`,
  decks in entry order), above the sections of the current deck. Without any `group`, the sidebar
  only lists the current deck's sections as before.
- **In `<StoryGallery />`**: stories without a `group` appear first, then each non-empty group gets
  a heading (`<h2>` by default, or `headingLevel` from `2` to `6`, e.g. `headingLevel={3}`) above
  its grid. `<StoryGallery groups={false} />` keeps a single flat grid.
- **Order and undeclared groups**: empty groups are omitted; the others sort by explicit `order`,
  then declaration order in `publish.groups`, then first appearance in `publish.entries`. A `group`
  cited in `entries` without a matching `publish.groups` declaration uses its `id` as its label;
  declaring the same `id` twice in `publish.groups` is a config error.
- **Groups and series together**: a deck can carry a `group` and also belong to a `navigation`
  category; the category orders the « Next deck » card and the Contents drawer footer, while `group`
  organizes the sidebar and `<StoryGallery />`.

## Links to a slide

A deck opens on a slide with `?slide=4`, `#slide-4`, or `#<id>`, the `id` of a scene:

```md title="slides.md"
--- id=proof

# The proof
```

`/stories/lorem#proof` opens that slide. In the source of a deck, link to another deck by its file:

```md
As [the proof](./lorem.md#proof) shows, and [back to the start](./slides.md#intro).
```

The compiler writes the address of the page: on a site, the page of that story
(`/stories/lorem#proof`); with `recit build`, a link to the deck's own file becomes `#intro`. A file
the site does not publish, or an `id` none of its scenes has, is an error with the file and the line
of the slide.

## In the PDF

The bookmarks of a deck's PDF are its headings: a section named by `section=` gets one too, under
its own name. The bookmarks follow the order of the contents but not its nesting: every slide uses
`#`, so sections and slides are on one level.

## Limits

- In an MDX deck, a link to another deck's file is not rewritten: write the page's address.
- On a site, the sections of a deck are listed after the other pages of its category, not under the
  deck itself.
- The PDF's bookmarks are on one level.
