All jobs

Add a Sitemap to a SvelteKit App

Yes. An agent adds a sitemap.xml server route that lists your static pages and every article and profile from your API, points robots.txt at it, and opens a PR.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

The agent reads how the app gets its content before it writes a sitemap, because a sitemap is only useful if it lists what the server can render. In an app shaped like sveltejs/realworld, package.json has @sveltejs/kit ^2.52, svelte ^5.55, vite ^7.3 and @sveltejs/adapter-vercel ^6.3, with pnpm@10.20.0 as packageManager and a .nvmrc of 20. There is no test runner and no workflow directory; lint runs prettier --check .. svelte.config.js turns on runes and the Vercel adapter. Every page loads its data on the server: src/lib/api.js sends requests to https://api.realworld.show/api, src/routes/+page.server.js reads articles and articles/feed with limit and offset from page_size in src/lib/constants.js, src/routes/article/[slug]/+page.server.js reads one article and its comments, and src/routes/profile/@[user]/get_articles.js pages through an author's articles the same way. src/hooks.server.js reads the jwt cookie into locals.user. static/robots.txt allows everything and names no sitemap.

It adds src/routes/sitemap.xml/+server.js with a GET handler, the SvelteKit way to serve a non-page response. The handler builds the list in three parts. First the public static routes: /, /login and /register. Then every article: it calls api.get on articles with limit and offset, reads articlesCount from the first response and keeps paging until it has them all, and writes one url per /article/<slug> with the article's updatedAt as lastmod. Then one /profile/@<username> per distinct author seen in those articles, since the API has no endpoint that lists users. Pages that need a signed-in user, /editor, /settings and the /profile redirect, are left out on purpose. The base URL comes from url.origin on the request, so the same code is right on a preview deployment and in production.

The response is served with Content-Type: application/xml and a Cache-Control header with an s-maxage set through setHeaders, so Vercel's edge serves the sitemap from cache and the API is not paged through on every crawler visit. The XML is built by a small src/lib/sitemap.js with build_sitemap(entries) that escapes &, < and > in URLs, kept separate from the route so it can be checked without a network. static/robots.txt gets a Sitemap: line pointing at /sitemap.xml. The agent follows the repository's style: JavaScript with JSDoc type comments like /** @type {import('./$types').RequestHandler} */, tabs, single quotes, no semicolons where Prettier removes them.

Because the repository has no test runner, the agent adds vitest as a dev dependency with a test script, and writes src/lib/sitemap.test.js for the builder: a known set of entries produces the expected XML, special characters are escaped, and an empty list still produces a valid document. It also writes a test for the handler that stubs $lib/api and checks that an articlesCount larger than page_size makes the handler page through every offset. Before pushing it runs pnpm run lint and pnpm run build with the Vercel adapter, as a deployment would, and the new pnpm test.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "Add a sitemap to this SvelteKit app and open a pull request. Read package.json, svelte.config.js, src/hooks.server.js, src/lib/api.js, src/lib/constants.js, src/routes/+page.server.js, src/routes/article/[slug]/+page.server.js, src/routes/profile/@[user]/get_articles.js and static/robots.txt first. Add src/routes/sitemap.xml/+server.js with a GET handler that lists /, /login and /register, every /article/<slug> from the articles endpoint paged with limit and offset until articlesCount is reached with updatedAt as lastmod, and one /profile/@<username> per distinct author; leave out pages that need a signed-in user. Build the XML in src/lib/sitemap.js with escaping, use url.origin as the base, and set Content-Type and a Cache-Control with s-maxage through setHeaders. Add a Sitemap line to static/robots.txt. Add vitest with a test script and write tests for the builder and for paging. Keep the repository's JavaScript and JSDoc style. Run pnpm run lint, pnpm run build and pnpm test and paste the results in the 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 that adds src/routes/sitemap.xml/+server.js, src/lib/sitemap.js and its test, adds one line to static/robots.txt, and adds vitest with a test script to package.json and pnpm-lock.yaml. Nothing under src/routes that renders a page changes. The description shows a sample of the XML the handler produces, says which routes are listed and which are left out and why, and pastes the lint, build and test output.

A reviewer checks the list of static routes against the app's actual public pages, decides whether s-maxage matches how often articles are published, and confirms that the handler stops paging when the API reports articlesCount. They can open /sitemap.xml on the preview deployment the Vercel adapter produces and submit it in Search Console once merged.

Run it on every SvelteKit app without a sitemap

A team with several SvelteKit sites sends one POST /o/{org}/sessions per repository with this prompt and that repository in resources. Each run reads its own routes and data loaders, so a site built from Markdown files with import.meta.glob gets a prerendered sitemap and a site that reads an API gets a server route like this one, and each run opens its own pull request.

Give the API key a webhook_url and Rush POSTs run.completed when each turn ends, with the session_url to read the pull request and the test output from.

The use case this job follows, with its automation and trigger: Hand off a long task.

Why run it on Rush?

A sitemap that lists the wrong routes, misses articles past the first page, or serves XML that a parser rejects is worse than none, and none of those faults show in a code read. In a Rush sandbox the agent builds the app with the same adapter the deployment uses, runs the tests it wrote against a stubbed API with more articles than one page holds, and keeps every command and its output in the run's record, so the reviewer sees the paging and the escaping checked rather than described.

The route reuses src/lib/api.js and page_size from constants.js, so the sitemap pages through the API exactly the way the article list does, and when the page size changes the sitemap follows. There is no sitemap plugin to configure and no build step to add; one server route and one builder module, both in the repository's own JavaScript style.

Frequently asked questions

Why a server route instead of a prerendered file?

Because the articles come from an API at request time, not from the repository. A file generated at build time would go stale as soon as someone publishes. The +server.js route reads the API when a crawler asks and caches the answer at the edge through Cache-Control.

Does it list every article, or only the first page?

Every article. The handler reads articlesCount from the first response and requests further pages with offset until the count is reached, using the same page_size the article list uses. A test stubs the API with more articles than one page and asserts every offset was requested.

What about pages behind a login?

They are left out. /editor, /settings and the /profile redirect need a jwt cookie, so a crawler would get a redirect or an error. Only /, /login, /register, article pages and author profiles are listed.

Does it need a dependency for the XML?

No. The document is a template string in src/lib/sitemap.js with an escaping function for the URL text. The only new dependency is vitest, added so the builder and the paging have tests, since the repository has no test runner today.

More SvelteKit jobs

The same job on other stacks

Keep reading