Closed flexchar closed 1 year ago
Okay. After long tinkering I found that updating my nuxt.config.ts
to allowed me to render proper sitemap:
routeRules: {
'/': { static: true },
'/blog/**': { static: true },
'/sitemap.xml': {
swr: 3600, // this to keep it no older than one hour while having cached version
headers: { 'Content-Type': 'application/xml' }, // adding headers made it work in browser
},
},
modules: [
'@nuxtjs/tailwindcss',
'nuxt-icons',
'nuxt-simple-sitemap',
],
nitro: {
prerender: {
crawlLinks: true,
routes: ['/'], // removing from here solved the error but nothing else
}
},
hooks: {
async 'nitro:config'(nitroConfig) {
if (nitroConfig.dev) {
return;
}
const dynamicPosts = (await getBlogPages()).map(p => `/posts/${p.slug}`);
nitroConfig.prerender?.routes?.push(...dynamicPosts);
},
},
sitemap: {
// provide dynamic URLs to be included
urls: async () => {
const blogPages = await getBlogPages();
return blogPages.map(page => ({
loc: `/posts/${page.slug}`,
lastmod: new Date(page.created_at),
changefreq: 'daily',
priority: 0.8,
}));
},
}
I settle with netlify-edge
preset for now.
I had multiple issues where before if I didn't prerender it, I'd be able to see it however all updated at
dates would be the current time instead of real timestamps of articles.
Thanks, I'll keep this open to add the route rules for the sitemap
Describe the bug
I'm trying to deploy Nuxt 3 as a fully static site (I don't want SSR on functions as they slow down) on Netlify.
I can see an error in the logs:
Relevant parts from my Nuxt config
I've been playing a lot with this but doesn't seem like it wanna work nicely. I'm also having tough time understanding all the possible rendering options so I might have confused myself. But it seems that this time it's Nitro that struggles to prerender Sitemap file. Any ideas? :)
Reproduction
No response
System / Nuxt Info