Skip to content

CLI: --sitemap reads routes from the right side's sitemap - #67

Merged
tmashara merged 2 commits into
mainfrom
claude/issue-46-sitemap
Oct 29, 2026
Merged

tmashara merged 2 commits into
mainfrom
claude/issue-46-sitemap

Conversation

@tmashara

@tmashara tmashara commented Oct 29, 2026 •

Copy link
Copy Markdown
Owner

What

--sitemap[=<url-or-path>] adds the paths in the right side's sitemap to the routes. Bare --sitemap reads <right>/sitemap.xml. --sitemap=/sitemap-index.xml or a full URL picks another one. Prints Sitemap: <url>: N routes[, M files dropped] before Routes: N. --dry-run fetches the sitemap and lists the pairs.

Why

Listing every route by hand is the slowest part of setting up a run, and most sites already publish the list.

Design decisions

  • Right side's sitemap. Right is the reference (the base build or production), so its page list is the one to check against.
  • Host ignored. Every <loc>, for pages and for child sitemaps, is reduced to pathname + search and loaded on right. A local base build's sitemap names the production host (Astro site, next-sitemap, Hugo baseURL), so dropping other hosts would drop everything. The sitemap protocol already requires every URL to share one host. A deliberately cross-host sitemap would load foreign paths on right; those 404 or error visibly, and --dry-run shows them.
  • One sitemap-index level. Astro and next-sitemap emit an index by default. An index inside an index isn't followed.
  • Files dropped. Paths ending in an obvious non-page extension (.pdf, .xml, images, media, office docs, ...) are skipped. It's a denylist, so .php, .aspx and /v1.2 stay.
  • Explicit routes win. Routes from the CLI (or else the config) come first, as today. Sitemap paths follow in sitemap order, minus any path an explicit route already loads on either side. This is needed for correctness: a config route /a with its own before hook plus a plain sitemap /a would otherwise throw "two routes both read as /a". It also keeps /pricing::/plans from being repeated as a plain /plans.
  • Errors exit 2 without usage text: HTTP >= 400, fetch failure or a 10 s timeout, a body that isn't <urlset>/<sitemapindex> (for example an SPA fallback answering 200 with index.html), a sitemap with no page paths, or --sitemap= with no value.
  • Flag shape. The bare flag never consumes the next token, so renderdiff --sitemap http://l http://r keeps both origins. A value needs =.
  • No new dependency: a regex over <loc> (CDATA and the five XML entities handled) plus global fetch.

Cut from the issue

  • --include / --exclude globs: no other route filter exists in the CLI, and a child sitemap (--sitemap=/sitemap-blog.xml) or explicit routes already narrow the set. These can follow if wanted.
  • gzip .xml.gz served without Content-Encoding: the common generators don't emit it by default, and fetch already handles Content-Encoding: gzip. This can follow if wanted.

How tested

New tests/unit/sitemap.test.ts, which goes through --dry-run against a local node:http server standing in for right (no browser). It covers:

  • the host being ignored, dedupe, files dropped, CDATA and entities, and the count line
  • a sitemap index
  • --sitemap=<path>
  • explicit routes first and not repeated
  • a config route with a before hook against the same sitemap path
  • a bare --sitemap before the positional origins
  • every exit-2 case

cli-args.test.ts now checks that --help mentions --sitemap.

Run against main's src/cli.ts, those tests fail (9 failures). Without the covered-path filter, the two explicit-route tests fail. npm run typecheck, lint, format:check, npm test (302) and npm run test:visual (330) all pass.

Docs: README (non-goals line, flag table, routes paragraph, exit-2 row), the --help exit sentence, and the skill's SKILL.md / reference.md route guidance.

Fixes #46

🤖 Generated with Claude Code

tmashara and others added 2 commits October 29, 2026 17:52
Reads <right>/sitemap.xml (or --sitemap=<url-or-path>), follows one
sitemap-index level, reads every <loc> as a path on right whatever its
host, and drops file URLs. Routes given explicitly come first and the
sitemap doesn't repeat their paths.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… under exit 2

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tmashara
tmashara force-pushed the claude/issue-46-sitemap branch from cf44be0 to 9297c04 Compare October 29, 2026 16:52
@tmashara
tmashara merged commit fbd2f81 into main Oct 29, 2026
3 checks passed
@tmashara
tmashara deleted the claude/issue-46-sitemap branch October 29, 2026 16:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--sitemap: take routes from the reference's sitemap.xml

1 participant