next-sitemap doesn't exclude server-sitemap-index.xml
Unanswered
Spectacled bear posted this in #help-forum
Spectacled bearOP
I'm using the next-sitemap package to generate sitemaps.
I wonder why
I want two sitemap index files:
- domain.com/sitemap.xml
- domain.com/server-sitemap-index.xml
However currently I have:
- domain.com/sitemap.xml
- domain.com/next-sitemap.xml
- domain.com/server-sitemap-index.xml
Looks like this:
This is my
This is my
I wonder why
exclude: ['/server-sitemap-index.xml'... doesn't exclude /server-sitemap-index.xml from sitemap.xml?🤷♂️🤔I want two sitemap index files:
- domain.com/sitemap.xml
- domain.com/server-sitemap-index.xml
However currently I have:
- domain.com/sitemap.xml
- domain.com/next-sitemap.xml
- domain.com/server-sitemap-index.xml
Looks like this:
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<sitemap>
<loc>https://www.domain.com/sitemap-0.xml</loc>
</sitemap>
<sitemap>
<loc>https://www.domain.com/server-sitemap-index.xml</loc>
</sitemap>
</sitemapindex>This is my
next-sitemap.config.js:/** @type {import('next-sitemap').IConfig} */
const siteUrl = process.env.NEXT_PUBLIC_SITE_URL
module.exports = {
siteUrl: siteUrl,
sitemapSize: 50000,
generateRobotsTxt: true,
exclude: ['/server-sitemap-index.xml', '/sitemap/*'],
robotsTxtOptions: {
additionalSitemaps: [
`${siteUrl}/server-sitemap-index.xml`,
],
},
transform: async (config, path) => {
return {
loc: path,
}
}
}This is my
/app/server-sitemap-index.xml:import { getServerSideSitemapIndex } from 'next-sitemap'
import { getSitemapAmount } from '../mongoDbActions';
const siteUrl = process.env.NEXT_PUBLIC_SITE_URL
const maxSitemapLength = 50000
export async function GET(request: Request) {
const allCombisSitemapData = []
const numberOfSitemaps = await getSitemapAmount(maxSitemapLength)
for (let i = 0; i < numberOfSitemaps; i++) {
allCombisSitemapData.push(
`${siteUrl}/sitemap/${i}.xml`
)
}
return getServerSideSitemapIndex(allCombisSitemapData)
}