Auto-generate sitemap.xml with Rails on Render.com
With the launch of doevery.day, I decided I should register a sitemap. The site is built with Rails 7 and running on Render, so I set about finding an automated way to make this happen. Here’s what I came up with.
From there you should make sure you have a
robots.txt defined (docs). Here’s ours:
User-agent: * Disallow: Sitemap: https://doevery.day/sitemap.xml.gz
Finally, you need to update your render build script (mine is found in
this to your script:
bundle exec rake sitemap:refresh
And that should do it! You will have a sitemap after your next deploy.
(I’ll admit I did run this in my local environment to make sure my code worked. You should probably do that
rake sitemap:refresh:no_ping command. I forgot. I hope I didn’t make Google and Bing