Skip to content

fix: generate a single clean sitemap.xml, drop @astrojs/sitemap#26

Merged
enricopiovesan merged 1 commit into
mainfrom
fix/single-clean-sitemap
Jul 11, 2026
Merged

fix: generate a single clean sitemap.xml, drop @astrojs/sitemap#26
enricopiovesan merged 1 commit into
mainfrom
fix/single-clean-sitemap

Conversation

@enricopiovesan

Copy link
Copy Markdown
Collaborator

Summary

  • @astrojs/sitemap unconditionally wraps output in a sitemap-index.xml -> sitemap-N.xml pair — no config option skips this, even for a small 89-page site. The previous fix copied sitemap-0.xml over sitemap.xml, but the redundant index/sub-sitemap files were still sitting in the deployed output alongside the copy.
  • Replaced the dependency with a small postbuild script (scripts/generate-sitemap.mjs) that walks the real built dist/ directory and writes one flat sitemap.xml directly — no intermediate index, no byproduct files, can't drift from the real page set since it reads the actual build output.

Test plan

  • dist/ contains exactly one sitemap file (sitemap.xml), 89 URLs, homepage root URL included
  • 0 broken internal links across all 89 pages
  • robots.txt already points at /sitemap.xml
  • curl production after deploy: only /sitemap.xml exists, /sitemap-index.xml and /sitemap-0.xml now 404 (expected — they're gone)

🤖 Generated with Claude Code

@astrojs/sitemap unconditionally wraps its output in a
sitemap-index.xml -> sitemap-N.xml pair, even for a site this small
with no real need for the split. The previous fix worked around it by
copying the generated sitemap-0.xml over sitemap.xml post-build, but
that still left the redundant index/sub-sitemap files sitting in the
deployed output alongside the copy -- pure clutter with no purpose
once sitemap.xml has everything.

Replaced the dependency with a ~30-line postbuild script
(scripts/generate-sitemap.mjs) that walks the actual built dist/
directory and writes one flat sitemap.xml directly from the real
page files -- no intermediate index, no byproduct files, and it can
never drift from the real page set since it reads dist/ after the
build completes.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@enricopiovesan enricopiovesan merged commit 0e8f000 into main Jul 11, 2026
2 checks passed
@enricopiovesan enricopiovesan deleted the fix/single-clean-sitemap branch July 11, 2026 16:03
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.

1 participant