feat: add dynamic sitemap generation and API endpoint#1459
Open
kelvinkipruto wants to merge 6 commits intomainfrom
Open
feat: add dynamic sitemap generation and API endpoint#1459kelvinkipruto wants to merge 6 commits intomainfrom
kelvinkipruto wants to merge 6 commits intomainfrom
Conversation
Implement sitemap generation functionality with a new API endpoint at `/api/v1/sitemap`. The sitemap includes all published pages (excluding error pages) with proper URL formatting, last modified dates, and XML escaping. This improves SEO by providing search engines with an up-to-date sitemap. - Add sitemap.xml rewrite rule in Next.js config - Create sitemap API endpoint handler - Implement sitemap generation utilities including URL normalization and deduplication - Export getSitemapXml function from data layer
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
…dpoint - Validate that only GET requests are allowed, returning 405 for other methods - Add Cache-Control headers to improve performance and reduce server load - Wrap sitemap generation in try-catch to handle errors gracefully - Remove unnecessary escapeXml call for lastmod dates and simplify dedupe logic - Make getSitemapEntries function private to module
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
Change getSitemapXml from named to default export for consistent import patterns Add Sentry error capture to sitemap API endpoint for improved monitoring
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
kilemensi
reviewed
Apr 16, 2026
Member
kilemensi
left a comment
There was a problem hiding this comment.
👍🏽
- We have more pages than just
pagescollection e.g. most ofopportunitiescollection items also become pages. - If you've addressed all comments, please hide them/mark them as resolved. Otherwise, it's hard to review not knowing if you should comment on something that already has a comment or not.
Comment on lines
+121
to
+131
| const xmlEntries = entries | ||
| .map(({ url, lastModified }) => { | ||
| const lastModifiedNode = lastModified | ||
| ? `\n <lastmod>${lastModified}</lastmod>` | ||
| : ""; | ||
|
|
||
| return ` <url>\n <loc>${escapeXml(url)}</loc>${lastModifiedNode}\n </url>`; | ||
| }) | ||
| .join("\n"); | ||
|
|
||
| return `<?xml version="1.0" encoding="UTF-8"?>\n<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n${xmlEntries}\n</urlset>\n`; |
Member
There was a problem hiding this comment.
- Do we need to escape XML? e.g. https://nextjs.org/learn/seo/xml-sitemaps doesn't (and do we need this to be in
pages/apiinstead of justpages? - If it's going to be too big, we may need to look into streaming instead of creating the whole file in memory.
- Replace dynamic pathname generation with stored `pathname` field from CMS - Filter pages by `_status: "published"` instead of just excluding error pages - Remove XML escaping as URLs are already validated and safe - Add Sentry warning for pages missing pathname to aid debugging - Simplify code by removing deduplication and custom escape functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Implement sitemap generation functionality with a new API endpoint at
/api/v1/sitemap. The sitemap includes all published pages (excluding error pages).Fixes # (issue)
Type of change
Screenshots
Checklist: