# Add Reading Time to an Eleventy Blog

Yes. An agent adds a reading-time filter to your Eleventy blog, shows the minutes beside each post's date on the post and in the archive, and opens a PR.

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

## What the agent does

The agent starts from the templates that already show post metadata. In a blog like 11ty/eleventy-base-blog, every post under `content/blog/` gets `tags: ["posts"]` and `layout: layouts/post.njk` from `content/blog/blog.11tydata.js`. That layout renders a `<ul class="post-metadata">` with one `<time>` built from `page.date | htmlDateString` and `page.date | readableDate`, then the tag links, then `{{ content | safe }}`. The archive and the home page both include `_includes/postslist.njk`, where each entry shows the title and a `<time class="postlist-date">` with `readableDate("LLLL yyyy")`. Those two places are where a reading time belongs, and the agent adds it to both rather than inventing a third.

Filters live in `_config/filters.js`, which `eleventy.config.js` loads as a plugin: `readableDate` and `htmlDateString` on Luxon, `head`, `min`, `getKeys`, `filterTagList` and `sortAlphabetically`. The agent adds a `readingTime` filter there, next to them, that takes a post's raw Markdown, drops fenced code blocks and HTML tags, counts whitespace-separated words and divides by a words-per-minute constant declared at the top of the filter, rounding up to a minimum of one minute. It reads the raw input rather than the rendered `content` so the post page and the archive list agree exactly, and so `thirdpost.md`, whose body is mostly a code sample and a diff, is not credited for every token inside its fences.

The post layout gets a second `<li>` in `.post-metadata` with the minutes, and `postslist.njk` gets the same value after the date, styled with the existing `.postlist-date` rule in `css/index.css` so it inherits the smaller size and gray the date already has. The CSS file is inlined into the page bundle by `_includes/layouts/base.njk`, so one new rule for the metadata item is enough and no build step changes. The Atom feed from `@11ty/eleventy-plugin-rss` and `content/sitemap.xml.njk` are left as they are.

The proof is the built site. The agent runs `npm install` and `npm run build`, which is `npx @11ty/eleventy` on the Node 22 that `.nvmrc` pins, then reads `_site/blog/thirdpost/index.html`, `_site/blog/fifthpost/index.html` and `_site/blog/index.html` to show the minutes on the longest sample post, on the shortest one and in the archive list, and confirms that `_site/feed/feed.xml` is byte-for-byte what it was. If `eleventy.config.js` has `draft` handling, as the base blog does through its `drafts` preprocessor and `_data/eleventyDataSchema.js`, the filter is applied after that, so a draft hidden from the build never shows up with a time.

## Start it with one API call

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

```json
{
  "agent": "claude",
  "input": "Add an estimated reading time to this Eleventy blog. Read eleventy.config.js, _config/filters.js, _data/metadata.js, content/blog/blog.11tydata.js, _includes/layouts/post.njk, _includes/postslist.njk, css/index.css and every post under content/blog first. Add a readingTime filter in _config/filters.js that counts the words of a post's raw Markdown after removing fenced code blocks and HTML tags, divides by a words-per-minute constant declared at the top of the filter, and rounds up to at least one minute. Show the result as a new item in the post layout's post-metadata list and after the date in postslist.njk, reusing the existing date styling. Do not change the feed, the sitemap or any post. Run npm install and npm run build, quote the rendered metadata of the longest and the shortest post and one archive entry from _site, and open a pull request.",
  "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

What comes back is a pull request on its own branch that touches `_config/filters.js` (the new filter and its constant), `_includes/layouts/post.njk` (one new metadata item), `_includes/postslist.njk` (the minutes after each date) and `css/index.css` (one rule). No post, no data file and no plugin configuration changes, and `package.json` gains no dependency, because the filter is a few lines of plain JavaScript.

The description quotes the rendered `post-metadata` list of the longest and the shortest sample post and one archive entry, so a reviewer sees the minimum of one minute hold on the tiny post and sees the code-heavy post counted sensibly, without building anything. Every command the agent ran, the build log included, is in the transcript at `GET /o/{org}/sessions/{id}/messages` beside its output.

Before merging, a reviewer picks the words-per-minute constant they want, decides whether the archive list should show the minutes or only the post page, and checks the wording for a one-minute post. A follow-up message to the same session can change the constant, move the value into `eleventyComputed` data so other templates can read it, or add it to the Atom feed's entries.

## Run it on every Eleventy site you maintain

A studio or a team that keeps several Eleventy blogs starts one run per repository with one `POST /o/{org}/sessions` each, the repository in `resources` and this prompt as `input`. Each run clones its own repository through the GitHub App installation that covers it, builds in its own sandbox and opens its own pull request, so ten sites mean ten pull requests to review the same morning.

A key may have at most `max_concurrent` runs in progress at once, four by default, and a loop over more Eleventy sites than that neither waits nor spaces its calls: the runs past the limit come back `202` with `status: "queued"` and start when a slot frees. Send a `request_id`, one UUID per repository, so a retried call returns the run it already started instead of opening a second pull request on the same site.

## Why run it on Rush?

A reading time is a small feature with a surprising number of ways to be slightly wrong: counting the front matter, counting a code sample, showing zero minutes on a short post, or computing it from rendered HTML in one place and from Markdown in another so the two disagree. The agent reads the real layout chain and the real filters file, writes the filter once, and checks the built HTML rather than trusting the template, with the Node version from `.nvmrc` and the packages from the lockfile.

The pull request carries the rendered metadata for three kinds of post in its description and the full build output in the transcript, so the review is a read of one filter and two templates. The laptop stays free, and the same request can run against every blog you maintain at once, each in its own sandbox.

## Frequently asked questions

### Why count the raw Markdown instead of the rendered HTML?

So the post page and the archive list agree. In the post layout the rendered `content` is available, but in `postslist.njk` only the collection item is, and Eleventy exposes a post's raw input on it. One filter over one input gives one number everywhere, and stripping fenced code blocks is easier on Markdown than on highlighted HTML.

### Does a code-heavy post get a huge reading time?

No. The filter drops fenced code blocks before counting, so a post like the base blog's `thirdpost.md`, which is mostly a code sample and a diff, is counted on its prose. The pull request says so and shows that post's rendered minutes, so a reviewer who would rather count code can ask for the fence handling to be removed.

### Will this show up in the Atom feed?

Not unless you ask. The feed is built by `@11ty/eleventy-plugin-rss` from the `posts` collection with a limit of ten entries, and the agent leaves that configuration and the generated `_site/feed/feed.xml` untouched. A follow-up message can add the minutes to each entry's summary.

### Can I change the words-per-minute figure later?

Yes. It is one named constant at the top of the `readingTime` filter in `_config/filters.js`, and the pull request description points at it. Changing it and rebuilding updates every post and every list entry at once, because nothing is stored in the posts.

## More Eleventy jobs

- [Add Related Posts by Shared Tags to an Eleventy Blog](https://getrush.ai/run/add-related-posts/eleventy/)
- [Add Search to an Eleventy Blog from a Linear Issue](https://getrush.ai/run/add-search/eleventy/)
- [Add Security Headers and a CSP to an Eleventy Site](https://getrush.ai/run/add-security-headers/eleventy/)

## The same job on other stacks

- [Add Reading Time to Posts in a Gatsby Blog](https://getrush.ai/run/add-reading-time/gatsby/)
- [Add Reading Time to a Hugo Blog](https://getrush.ai/run/add-reading-time/hugo/)
- [Add Reading Time to a Jekyll Blog](https://getrush.ai/run/add-reading-time/jekyll/)

## 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/)
