# Add Last Updated Dates to an mdBook Site

Yes. An agent adds a preprocessor that stamps each chapter with its last commit date and link, orders it after translation, and proves it in the book's own CI steps.

[Run this on Rush](https://cloud.getrush.ai/run/add-last-updated-dates/mdbook/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent reads the book's configuration and its build before choosing a tool. In a book laid out like rust-lang/rust-by-example, `book.toml` sets `git-repository-url` and an `edit-url-template` pointing at `edit/master/{path}`, turns on `hash-files`, adds `theme/css/language-picker.css`, and declares a `gettext` preprocessor marked `optional = true` with `after = ["links"]` that renders the translations kept as `po/es.po`, `po/ja.po`, `po/ko.po` and `po/zh.po`. `theme/head.hbs` injects a language picker into the page's right-hand buttons at load time. `.github/workflows/rbe.yml` pins `MDBOOK_VERSION: 0.5.1`, checks out with `fetch-depth: 0` and the comment that the full history is needed, installs `mdbook-i18n-helpers` at `0.4.0` with `cargo install --locked`, runs `mdbook test`, `mdbook build`, the Rust repository's `linkcheck.sh`, and then one `mdbook build -d book/$po_lang` per language with `MDBOOK_BOOK__LANGUAGE` set.

The date comes from git, not from the file system, because a checkout gives every file the same modification time. The agent adds the `mdbook-last-changed` preprocessor, which reads each chapter's last commit through `git log`, appends a line with the date and a link to the commit built from `git-repository-url`, and needs nothing in the theme. It installs the preprocessor's current release in the sandbox, builds the book with the pinned mdBook 0.5.1 and checks that the footer appears on `index.html` and a nested chapter before writing the version into the workflow beside the i18n helpers, with the same `--locked` flag. If the current release refuses that mdBook, the run says which release built and pins that instead.

Ordering is the part a reader would miss. The footer is generated text, so it must not reach the translation step: the preprocessor is declared `after = ["gettext"]` so the dated line is added once the chapter has been translated and never lands in the `po/` messages that `mdbook-xgettext` extracts, where a date that changes every commit would churn every file. The language builds in the workflow then stamp each translated chapter with the same commit as its English source, because they read the same Markdown file's history.

Proof is the workflow's own sequence run in the sandbox: `mdbook test` to show the Rust snippets still compile, `mdbook build` with the footer visible in the output, `linkcheck.sh --all rust-by-example` to show the commit links resolve, and the four translated builds. A shallow clone makes every chapter look new, so the run fetches the full history first, as the workflow does with `fetch-depth: 0`, and the pull request shows one chapter's footer naming a commit from years back next to a recently edited one.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Add last updated dates to every chapter of this mdBook. Read book.toml, theme/head.hbs, README.md and .github/workflows/rbe.yml first, and fetch the full git history, since the dates come from git log. Add the mdbook-last-changed preprocessor to book.toml, declared after the gettext preprocessor so the generated footer never enters the po/ messages, using the existing git-repository-url for the commit links. Install it in the sandbox, build with the mdBook version the workflow pins, confirm the footer on the index page and a nested chapter, and pin the preprocessor's release in the workflow with cargo install --locked beside mdbook-i18n-helpers. Run mdbook test, mdbook build, the linkcheck step and the translated builds for every language the workflow lists. Open a pull request that shows one chapter's footer with an old commit and one with a recent commit, and the output of each step.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

The pull request changes `book.toml` and `.github/workflows/rbe.yml` and nothing under `src/`, `po/` or `theme/`. Its description pastes the install step, the `mdbook build` output, two chapter footers copied from the built HTML, the linkcheck result and the per-language build groups, so a reviewer sees the exact line each page gains and that the Rust examples still compile.

Every chapter, in every language, ends with the date of its last change and a link to that commit on the repository's host, which tells a reader whether a page reflects a recent edition of the language. The page edit links, search, folding and the language picker are untouched, since the preprocessor changes Markdown and not the theme.

Before merging, a reviewer checks that the deployment that publishes the book also checks out the full history, because a shallow checkout there would stamp every chapter with the deploy date, and decides whether a chapter touched only by a whole-book formatting commit should show that commit or be excluded.

## Run it on every mdBook repository

A team with several books sends this body once per repository to `POST /o/{org}/sessions` from a script, each with its own repository in `resources` and a `request_id` that is a UUID v5 of the repository's full name, so a retried call returns the run already started. Each run reads its own `book.toml`: a book with no translation step declares the preprocessor with no ordering, one that already overrides `theme/index.hbs` gets the footer placed by the template instead, and one whose workflow installs mdBook with `cargo install` gets the preprocessor pinned the same way.

Each run opens its own pull request on its own branch. `GET /o/{org}/sessions` lists them newest first and the key's `webhook_url` receives a `run.completed` per run with the pull request in `result`, so the person who started the batch reads every build log from one place.

## Why run it on Rush?

A last-updated footer is a two-line change that is wrong in three quiet ways: the file date of a fresh checkout, a generated line that lands in the translation catalogue, and a shallow clone on the build host. The agent reads the workflow's history setting and the preprocessor order before writing, and proves the output with the same mdBook release the workflow pins rather than whatever `cargo install` gives today.

The run keeps every command and its output, so the reviewer reads the build and the linkcheck without a Rust toolchain or the nightly `rust-docs` the tests need. Several books can be stamped at once, each in its own sandbox, and one whose theme already prints a date gets only the ordering fix.

## Frequently asked questions

### Why a preprocessor instead of editing the theme?

The theme's templates receive the chapter's path but not its history, so a template cannot print a commit date on its own. A preprocessor runs before rendering with access to the working tree and `git log`, which is where the date lives.

### Will this change the translations?

No. The preprocessor runs after `gettext`, so the translated chapters get the footer added to their output and the `po/` catalogues see no new message. The pull request shows a Japanese page's footer to prove it.

### What happens on a shallow clone?

Every chapter's last commit becomes the clone's single commit, and every footer shows today. The workflow already uses `fetch-depth: 0`; the run does the same in its sandbox, and the pull request asks the reviewer to confirm the publishing job does too.

### Does it slow the build?

It runs one `git log` per chapter, and the build still finishes inside the same workflow step. The pull request pastes the build's timing so a reviewer can compare it with the previous run.

## More mdBook jobs

- [Add External Link Checking to an mdBook](https://getrush.ai/run/add-link-checking/mdbook/)
- [Add llms.txt to an mdBook Site](https://getrush.ai/run/add-llms-txt/mdbook/)
- [Add Mermaid Diagrams to an mdBook](https://getrush.ai/run/add-mermaid-diagrams/mdbook/)

## The same job on other stacks

- [Show Last Updated Dates on MkDocs Pages](https://getrush.ai/run/add-last-updated-dates/mkdocs/)
- [Show Last-Updated Dates on a Pelican Blog](https://getrush.ai/run/add-last-updated-dates/pelican/)
- [Add Last Updated Dates to Sphinx Docs](https://getrush.ai/run/add-last-updated-dates/sphinx/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
