Skip to content

Conversation

Slackluky
Copy link

Changes

New sitemap optional configuration for named sitemap files chunking strategy

Adds a chunks option to the sitemap configuration schema.
This allows users to define custom chunking strategies for
generating sitemaps, providing flexibility in how the sitemap
is split into multiple files.

			integrations: [
				sitemap({
					serialize(item) {
						return item
					},
					chunks: {
						'blog': (item) => {
							if (/blog/.test(item.url)) {
								item.changefreq = 'weekly';
								item.lastmod = new Date();
								item.priority = 0.9;
								return item;
							}
						},
						'glossary': (item) => {
							if (/glossary/.test(item.url)) {
								item.changefreq = 'weekly';
								item.lastmod = new Date();
								item.priority = 0.9;
								return item;
							}
						}
					},
				}),
			],

Testing

image image

Docs

yes, to add optional configurations for the chunks

@withastro/maintainers-docs for feedback!

Adds the ability to split sitemap generation into chunks based on
customizable logic. This allows for better management of large
sitemaps and improved performance.

The new `chunks` option in the sitemap configuration allows users to
define functions that categorize sitemap items into different chunks.
Each chunk is then written to a separate sitemap file.

This change introduces a new `writeSitemapChunk` function to handle
the writing of individual sitemap chunks.
Adds a `chunks` option to the sitemap configuration schema.
This allows users to define custom chunking strategies for
generating sitemaps, providing flexibility in how the sitemap
is split into multiple files.
The empty callback function in the `writeSitemap` function was
causing unnecessary function calls. This commit fixes this by
removing the empty callback.
This commit adds a test fixture to verify the sitemap chunking
functionality. It includes a configuration file, dependencies,
and several pages to simulate a real-world scenario.
Adds changeset to document the new sitemap chunking feature.
This feature allows splitting sitemap generation into chunks
based on customizable logic, improving management of large
sitemaps and performance.
Feature(sitemap): named files chunking strategy
Copy link

changeset-bot bot commented Oct 1, 2025

🦋 Changeset detected

Latest commit: c510a4c

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the pkg: integration Related to any renderer integration (scope) label Oct 1, 2025
Feature/sitemap chunking strategy --fix lockfiles
The import order of `AstroConfig` has been moved to align
with other imports, improving code readability and
consistency. This change ensures that type imports are
grouped together, making the codebase easier to maintain.
Simplify the chunk file test by using `path.resolve` and
`includes` for better readability and maintainability.
This change improves the test's clarity without altering
its functionality.
The tests were failing intermittently because the `readXML` function
was not properly resolving the file path. This commit updates the
`readXML` function to use `fixture.readFile` to ensure that the file
path is resolved correctly. Additionally, the `flatMapUrls` function
is now async to ensure that the `readXML` function is awaited.
@ascorbic
Copy link
Contributor

ascorbic commented Oct 3, 2025

Is this a breaking change?

@Slackluky
Copy link
Author

Slackluky commented Oct 4, 2025

no, it only add an optional chunk configuration in sitemap integration, i have added a testing file and fixture to sitemap integration module and all tests passed successfully


for (const item of urlData) {
// Await the asynchronous operation
const collect = await Promise.resolve(cb(item));
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does this need the Promise.resolve()?

Copy link
Author

Choose a reason for hiding this comment

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

The Promise.resolve() call is indeed necessary in this case. The callback function cb provided in the chunks option can return either a direct SitemapItem object or a Promise that resolves to a SitemapItem object. Promise.resolve() ensures that the result is always a Promise, allowing for consistent handling of both synchronous and asynchronous results.

Slackluky and others added 5 commits October 13, 2025 21:34
The previous changeset incorrectly marked the sitemap chunking feature as a major change. This commit corrects the changeset to reflect that it is a minor feature addition.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg: integration Related to any renderer integration (scope)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants