Hi everyone,
I'm working on a project using the aem-boilerplate-commerce in Edge Delivery Services and need to generate a sitemap-index.xml that references other sitemaps like categorias-sitemap.xml, productos-sitemap.xml, etc.
Here’s an example of what I’m trying to achieve:
<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<sitemap>
<loc>https://mydomain.com/sitemap-content.xml</loc>
</sitemap>
<sitemap>
<loc>https://mydomain.com/categorias-sitemap.xml</loc>
</sitemap>
<sitemap>
<loc>https://mydomain.com/productos-sitemap.xml</loc>
</sitemap>
<sitemap>
<loc>https://mydomain.com/content-sitemap.xml</loc>
</sitemap>
</sitemapindex>
In addition to serving this index, I’d also like to ask for suggestions on how to generate the content of each individual sitemap — especially for categories and products.
Are there any best practices or examples on how to fetch and structure this data in the context of aem-boilerplate-commerce?
For instance:
Should the product and category data be fetched from Adobe Commerce APIs and written to XML manually?
Is there a preferred way to automate this or generate it as part of the build/deploy process?
Any guidance, tips, or examples would be greatly appreciated.
Thanks in advance!
Solved! Go to Solution.
Topics help categorize Community content and increase your ability to discover relevant content.
Views
Replies
Total Likes
Hi @olsalas711,
1. Where to generate the sitemaps: In Edge Delivery Services (EDS), you typically:
Generate sitemaps as .xml.js pages (just like .plain.html.js)
Deploy them into the EDS GitHub repo (eg. pages/sitemap-index.xml.js)
These pages run server-side and can fetch data from APIs, then output raw XML.
2. Implementation steps
a. sitemap-index.xml.js (Sample)
export const content = async () => {
return `
<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<sitemap><loc>https://yourdomain.com/categorias-sitemap.xml</loc></sitemap>
<sitemap><loc>https://yourdomain.com/productos-sitemap.xml</loc></sitemap>
<sitemap><loc>https://yourdomain.com/content-sitemap.xml</loc></sitemap>
</sitemapindex>
`.trim();
};
export const headers = {
'Content-Type': 'application/xml',
};
Place this file in your repo: pages/sitemap-index.xml.js
b. productos-sitemap.xml.js (Sample using Commerce API)
import fetch from 'node-fetch';
export const content = async () => {
const products = await fetch('https://your-commerce-api.com/products')
.then(res => res.json());
const urls = products.map(p => `
<url>
<loc>https://yourdomain.com/product/${p.slug}</loc>
<lastmod>${new Date(p.updated_at).toISOString()}</lastmod>
<changefreq>weekly</changefreq>
<priority>0.8</priority>
</url>`).join('');
return `
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
${urls}
</urlset>
`.trim();
};
export const headers = {
'Content-Type': 'application/xml',
};
You can do similar for categorias-sitemap.xml.js, calling your categories API.
3. Here is how ypu can automate the data fetching
Fetch product/category data from Adobe Commerce GraphQL API or REST API
You can cache results locally if your API is slow, using Edge caching
Run this logic in .xml.js files — they behave like serverless functions
Hi @olsalas711,
1. Where to generate the sitemaps: In Edge Delivery Services (EDS), you typically:
Generate sitemaps as .xml.js pages (just like .plain.html.js)
Deploy them into the EDS GitHub repo (eg. pages/sitemap-index.xml.js)
These pages run server-side and can fetch data from APIs, then output raw XML.
2. Implementation steps
a. sitemap-index.xml.js (Sample)
export const content = async () => {
return `
<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<sitemap><loc>https://yourdomain.com/categorias-sitemap.xml</loc></sitemap>
<sitemap><loc>https://yourdomain.com/productos-sitemap.xml</loc></sitemap>
<sitemap><loc>https://yourdomain.com/content-sitemap.xml</loc></sitemap>
</sitemapindex>
`.trim();
};
export const headers = {
'Content-Type': 'application/xml',
};
Place this file in your repo: pages/sitemap-index.xml.js
b. productos-sitemap.xml.js (Sample using Commerce API)
import fetch from 'node-fetch';
export const content = async () => {
const products = await fetch('https://your-commerce-api.com/products')
.then(res => res.json());
const urls = products.map(p => `
<url>
<loc>https://yourdomain.com/product/${p.slug}</loc>
<lastmod>${new Date(p.updated_at).toISOString()}</lastmod>
<changefreq>weekly</changefreq>
<priority>0.8</priority>
</url>`).join('');
return `
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
${urls}
</urlset>
`.trim();
};
export const headers = {
'Content-Type': 'application/xml',
};
You can do similar for categorias-sitemap.xml.js, calling your categories API.
3. Here is how ypu can automate the data fetching
Fetch product/category data from Adobe Commerce GraphQL API or REST API
You can cache results locally if your API is slow, using Edge caching
Run this logic in .xml.js files — they behave like serverless functions
Hi Santosh,
Quick follow‑up question on the flow:
Right now I have /pages/sitemap‑index.xml.js in the repo.
When I hit the file directly ( .../pages/sitemap‑index.xml.js?plain=1 ) I see the code.
But calling /sitemap‑index.xml on the same branch still returns 404 (or the fallback sitemap if the cache isn’t flushed).
Do I need an extra script or build step to “materialise” a sitemap‑index.xml file, or does EDS automatically execute the .xml.js and stream the XML when that route is requested?
In other words, is the next step simply to make sure the CDN cache is purged and the route isn’t being shadowed by a static file / YAML, or do I need to wire up some additional handler that calls the JS and writes the XML out?
Thanks a lot!
Views
Replies
Total Likes
Hi JuanManuel_Pe,
you don’t need to create an index with a `.js` extension in your GitHub repo, just call it `sitemap-index.xml` with its plain XML content, and it’ll get delivered as-is.
Kind regards
Dominique
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies