# Add Pagination to an Eleventy Blog Archive

Yes. An agent paginates your Eleventy archive with Eleventy's own pagination front matter, keeps the post numbering continuous, adds prev and next links, opens a PR.

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

## What the agent does

The agent starts with how the archive is built today, because Eleventy's pagination changes what a template receives and the base blog's list include has expectations of its own. In a site made from 11ty/eleventy-base-blog, `content/blog.njk` is the Archive page: its front matter sets `eleventyNavigation` with the key `Archive`, it assigns `collections.posts` to `postslist` and includes `_includes/postslist.njk`. That include renders a reversed ordered list, `<ol reversed class="postlist">`, pipes the posts through the `reverse` filter so the newest comes first, and seeds a CSS counter from `postslistCounter or postslist.length` so the numbers count down from the total. `content/index.njk` already uses the `head` and `min` filters from `_config/filters.js` to show the three latest posts and links to the archive with `<a href="blog.njk">`, which the `InputPathToUrlTransformPlugin` in `eleventy.config.js` turns into the archive's URL at build time.

The agent then reads the one place the repository already paginates, `content/tag-pages.njk`, which sets `pagination` with `data: "collections"`, `size: 1`, `alias: "tag"` and a `permalink` function under `eleventyComputed`. It follows that pattern in `blog.njk`: `pagination.data` becomes `collections.posts`, `size` the page length from the prompt, `reverse: true` so the chunks are cut from newest to oldest, and the permalink is `/blog/` for the first page and `/blog/page/<n>/` from the second, with `n` as `pagination.pageNumber + 1` because the page number is zero-based. Two details decide whether the result looks right. The include reverses its input a second time, so the agent passes `pagination.items | reverse` as `postslist` rather than the chunk itself; otherwise each page would run oldest to newest while the pages run newest to oldest. And it sets `postslistCounter` from the total post count minus the posts on earlier pages, so the countdown continues across pages instead of restarting at the page length.

Navigation gets the same care. `eleventyNavigation` in the front matter would be copied onto every generated page, so the agent moves it under `eleventyComputed` and returns it only when `pagination.pageNumber` is zero, keeping one Archive entry in the header menu that `_includes/layouts/base.njk` builds from `collections.all | eleventyNavigation`. Below the list it adds a previous and next block using `pagination.href.previous` and `pagination.href.next`, reusing the `links-nextprev` classes that `css/index.css` already defines for the post layout's neighbouring-post links, so no new CSS enters the bundle. The home page's `more posts can be found in the archive` link and the Atom feed from `@11ty/eleventy-plugin-rss`, which reads the `posts` collection with its own `limit: 10`, are left alone.

To prove it, the agent installs with `npm ci` on Node 22 from `.nvmrc` and runs `npm run build`, which is `npx @11ty/eleventy` with `content` as input and `_site` as output. The sample repository publishes four posts, since `fifthpost.md` is a draft that the `drafts` preprocessor drops during a build, so a page size of ten would never produce a second page. The agent therefore builds once with `size: 2` to see `_site/blog/page/2/index.html` appear with the right posts, numbers and links, then sets the size the prompt asks for and builds again, and quotes both results in the pull request.

## Start it with one API call

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

```json
{
  "agent": "claude",
  "input": "Paginate the blog archive page of this Eleventy site, ten posts per page, newest first. Read eleventy.config.js, content/blog.njk, content/tag-pages.njk, content/index.njk, _includes/postslist.njk and _config/filters.js first, and use Eleventy's built-in pagination in the same way tag-pages.njk does. Keep /blog/ as the first page and put later pages under /blog/page/<n>/. Keep the reversed numbering in postslist.njk continuous across pages, keep a single Archive entry in the header navigation, and add previous and next links using the existing links-nextprev styles. Build the site with npm run build on the Node version in .nvmrc, check the generated pages, and open a pull request that shows the page list.",
  "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 changes one file, `content/blog.njk`: pagination front matter, the computed permalink and navigation entry, the reversed page items handed to the include with a continued counter, and the previous and next block. `_includes/postslist.njk`, `_config/filters.js`, `css/index.css` and `eleventy.config.js` are unchanged, so the home page, tag pages and feed render exactly as before.

The description lists the pages the build produced, with the posts on each and the counter value they start from, quotes the previous and next markup from a middle page, and explains the double reversal in one sentence so the next person who edits the template does not undo it. It also notes that `content/sitemap.xml.njk` walks `collections.all` and therefore lists the new pages, and leaves to the reviewer whether that is wanted.

Before merging, a reviewer checks the page size against how often the blog publishes, confirms `/blog/` still answers and that `/blog/page/1/` is not generated, and opens the Archive link in the header on a later page to see that it points at the first one.

## Run it on every terminal hand-off

A writer who notices the archive has grown past one screen starts this from the terminal with this body and the repository in `resources`, then goes back to writing. The run reads the real templates and filters, so the pagination lands in the existing include and counter rather than in a second list component.

Send a `request_id`, a UUID, in the body so a retried start returns the run it already began. When the turn ends, `GET /o/{org}/sessions/{id}` names the pull request, and a follow-up through `POST /o/{org}/sessions/{id}/messages`, for example to change the page size or to add page numbers between the previous and next links, wakes the parked sandbox where it left off.

## Why run it on Rush?

Pagination in Eleventy is a few lines of front matter, but on this layout the obvious lines produce a list that runs backwards within each page and restarts its numbering at the page length. The agent reads the include and the counter before it writes, follows the repository's own tag-page pattern, and checks the generated HTML rather than assuming.

On Rush the build runs in the agent's own sandbox on the Node version the repository pins, and the transcript keeps the build output and the pages it inspected, so the pull request's claims about which posts land on which page can be checked by anyone on the team. The same body paginates any Eleventy site built from this blog, each in its own sandbox.

## Frequently asked questions

### Will the archive's URL change?

No. The first page keeps `/blog/`, because the computed permalink returns it when `pagination.pageNumber` is zero, and only pages from the second onwards live under `/blog/page/<n>/`. Links to the archive from the home page and the header keep working.

### Why does the template reverse the items when pagination already has reverse set?

`postslist.njk` reverses whatever it is given so the newest post is first. With `reverse: true` the chunks are cut newest first, and passing a chunk straight through would reverse it again. Handing the include `pagination.items | reverse` restores the order on each page.

### What happens to the post numbers?

The include seeds a CSS counter from `postslistCounter`, so the agent sets that to the total minus the posts shown on earlier pages. Page one counts down from the total, page two continues from where page one stopped, and the numbers match the single-page archive readers had before.

### Does the feed or the home page change?

No. The Atom feed is produced by `@11ty/eleventy-plugin-rss` from the `posts` collection with its own limit, and `index.njk` takes the three latest posts with the `head` filter. Neither reads `blog.njk`, so neither sees the pagination.

## More Eleventy jobs

- [Add Reading Time to an Eleventy Blog](https://getrush.ai/run/add-reading-time/eleventy/)
- [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/)

## The same job on other stacks

- [Add Cursor Pagination to a FastAPI Endpoint from a Linear Issue](https://getrush.ai/run/add-pagination/fastapi/)
- [Add Pagination to a Gatsby Blog Index](https://getrush.ai/run/add-pagination/gatsby/)
- [Add Pagination to a Jekyll Blog](https://getrush.ai/run/add-pagination/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/)
