Skip to content

Add support for SitemapIndex in metadata route resolver #81001

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: canary
Choose a base branch
from

Conversation

nimamoosa
Copy link

This PR introduces a new SitemapIndex type and extends the resolveRouteData function to properly generate sitemap index XML files.
With this enhancement, Next.js can natively support sitemap index files, offering improved flexibility and better sitemap management for applications.

@ijjk
Copy link
Member

ijjk commented Jun 27, 2025

Allow CI Workflow Run

  • approve CI run for commit: 1ccc213

Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer

@@ -149,9 +149,33 @@ export function resolveManifest(data: MetadataRoute.Manifest): string {
return JSON.stringify(data)
}

export function resolveSitemapIndex(data: MetadataRoute.SitemapIndex): string {
let content = '<?xml version="1.0" encoding="UTF-8"?>\n'
content += '<sitemapindex xmlns="https://www.sitemaps.org/schemas/sitemap/0.9">\n'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sitemap index namespace URL should use the standard HTTP protocol rather than HTTPS. According to the official sitemap protocol specification, the correct namespace is http://www.sitemaps.org/schemas/sitemap/0.9.

While modern browsers handle both protocols, some sitemap validators and parsers strictly check for the exact namespace URI as defined in the specification. Using the incorrect protocol may cause validation failures or compatibility issues with certain tools.

Consider updating the namespace URL to ensure maximum compatibility:

<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
Suggested change
content += '<sitemapindex xmlns="https://www.sitemaps.org/schemas/sitemap/0.9">\n'
content += '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n'

Spotted by Diamond

Is this helpful? React 👍 or 👎 to let us know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants