I am BARRY HESS > Blog

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.

First I installed the sitemap_generator gem. This will handle the grunt work. The documentation does a good job getting you going and provides for most of the details you’ll need.

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 ./bin/render-build.sh. Add 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 with the rake sitemap:refresh:no_ping command. I forgot. I hope I didn’t make Google and Bing angry!)