Skip to content

fix: paginate blog sitemap to include all posts - #1293

Merged
miohtama merged 1 commit into
masterfrom
worktree-blog-sitemap-pagination
Jul 1, 2026
Merged

fix: paginate blog sitemap to include all posts#1293
miohtama merged 1 commit into
masterfrom
worktree-blog-sitemap-pagination

Conversation

@miohtama

@miohtama miohtama commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Why

The blog sitemap (/blog/sitemap.xml) only listed 100 posts even though 129 exist. The route requested limit=all from Ghost, but Ghost's Content API silently caps a single response at 100 posts ("limit":100,"pages":2 in the pagination metadata). Because the sitemap did a single request with no pagination, every post beyond the first 100 was dropped from search-engine indexing, and the gap grows as more posts are published.

Lessons learnt

  • Ghost Content API's limit=all is not honoured as "everything in one response" — it is capped at 100 per page. To fetch a complete collection you must paginate and follow meta.pagination.next until it is null.
  • Verify sitemap counts against Ghost's meta.pagination.total, not the number of <loc> entries returned by a single call — the two can silently diverge at the 100 boundary.
  • The integration suite fetches the blog sitemap against the live Ghost API (no mock), so pagination logic is better locked in with a deterministic unit test that stubs fetch.

Summary

  • Add getAllPosts() to src/lib/blog/client.ts — pages through Ghost with the maximum page size (100), following meta.pagination.next until exhausted, with a guard against a non-advancing next to avoid infinite loops.
  • Use getAllPosts() in src/routes/blog/sitemap.xml/+server.ts instead of the single getPosts({ limit: 'all' }) call.
  • Add src/lib/blog/client.test.ts covering multi-page (>100), max page size, and single-page cases.
  • Changelog entry.

Ghost's Content API silently caps a single response at 100 posts even when
limit=all is requested, so the blog sitemap dropped every post beyond the
first 100 (129 posts existed, only 100 were listed).

Add getAllPosts() which pages through Ghost with the maximum page size,
following meta.pagination.next until exhausted, and use it in the sitemap.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@miohtama
miohtama merged commit 4083263 into master Jul 1, 2026
5 checks passed
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