DEV Community

Discussion on: Sitemap with Next.js

Collapse
 
aralroca profile image
Aral Roca • Edited

For sitemap I dunno. But for the rss.xml I just added this inside the getStaticProps of my /blog page:

fs.writeFileSync('public/rss.xml', rssData)

I dunno if is a good way, but it works 🤷‍♂️

Maybe with sitemap is it possible to do something similar?

Collapse
 
tomgreeen profile image
tomgreeEn

Thanks, I hadn't thought of that. I'll give it a try.

Thread Thread
 
juliepranger profile image
Julie Pranger

Any luck with this? I am currently working through the same issue.

Thread Thread
 
tomgreeen profile image
tomgreeEn

I got it working locally fine but not yet pushed to server (I'm using vercel now). Not sure if that allows fs.writes.

Will report back when I've pushed to the server in the next few days.

Thread Thread
 
aralroca profile image
Aral Roca

I use fs.writes but I added on webpack finally...

webpack(config, { isServer }) {
    // Generate Sitemap + RSS on build time
    if (isServer) {
      require('./utils/generateSitemap')()
      require('./utils/generateRss')()
    }
 return config
}
Thread Thread
 
ftpublic profile image
flashthepublic

Thanks!
I tried your solution but do you know how to implement it when you are using Typescript? i need to import existing logic to get data that is written in TS

Thread Thread
 
aralroca profile image
Aral Roca

The next.config.js file has js extension. So looks difficult to use TypeScript here. One thing you can do is compile next.config.ts to next.config.js: github.com/vercel/next.js/issues/5...