I am experiencing an issue with the @nuxtjs/sitemap module in my Nuxt.js project. I’m trying to generate separate sitemaps for pages and posts from a WordPress API, but neither /posts-sitemap.xml nor /pages-sitemap.xml are being generated correctly. These sitemaps should be populated with slugs from WordPress posts and pages respectively.
Here’s the relevant part of my nuxt.config.ts:
export default defineNuxtConfig({
modules: [
'@nuxtjs/sitemap'
],
sitemap: [
{
path: '/pages-sitemap.xml',
hostname: 'https://nuxt3-website.nl',
cacheTime: 1000 * 60 * 15,
gzip: true,
routes: async () => {
const { data } = await axios.get('https://wordpress-site.nl/wp-json/wp/v2/pages');
return data.map(page => `/${page.slug}`);
}
},
{
path: '/posts-sitemap.xml',
hostname: 'https://nieuw.leertekenen.nl',
cacheTime: 1000 * 60 * 15,
gzip: true,
routes: async () => {
const { data } = await axios.get('https://wordpress-site.nl/wp-json/wp/v2/posts');
return data.map(post => `/blog/${post.slug}`);
}
}
]
});
When I try to access these sitemap URLs, I get a 404 error. I’ve confirmed that the axios requests to the WordPress API are successful and returning data. I’ve restarted the Nuxt server after making changes, but the issue persists.
Has anyone encountered a similar issue or can spot what might be going wrong here? Any insights or suggestions would be greatly appreciated!