benoitdemaegdt / nuxt3-sitemap

sitemap generation for nuxt3
55 stars 6 forks source link

static page generation #3

Closed codeflorist closed 2 years ago

codeflorist commented 2 years ago

if you want to support static site genreation also, this would be the code for it:

nuxt.hook('nitro:build:before', (nitro: Nitro) => {
    const paths = []
    nitro.hooks.hook('prerender:route', (route: PrerenderRoute) => {
        paths.push(route.route)
    })
    nitro.hooks.hook('close', async () => {
        const sitemap = await generateSitemap(paths)
        createSitemapFile(sitemap, filePath)
    })
})

of course the output-path should then be something like .output/public/sitemap.xml

benoitdemaegdt commented 2 years ago

Hey @codeflorist 👋

Thank you for this piece of code. It works great !

I added a section for generating sitemap for prerendered sites powered by @nuxt/content. 👉 https://github.com/benoitdemaegdt/nuxt3-sitemap#setup-for-a-dynamic-site-powered-by-nuxtcontent-with-prerendering

Also, I gave you credit for this at the end of instruction 😉