Recently, I advised a client on what I consider the top three Google services for his next social media project. Today I want to talk about a fourth Google service I think is helpful, but certainly not mandatory: Google Sitemaps.
Think about it, you’ve spent hours toiling away at your next awesome blog post. Why not help Google find that content it might not have found otherwise? Typically you have to manually build the sitemap. Then you have to manually submit the sitemap to Google. Who has time for all of that?
Rails Google Sitemap Code
Dynamically create a sitemap for your blog the Rails way. I know some of you are anxious to jump into the code, so let’s get to it:
Create the following Rails route:
UPDATE: Above route was written for Rails 2.3.8. Here is the updated route for Rails 3.0. Remaining code is Rails 3.0 complaint:
Create the following Rails controller to serve the Google sitemap requests:
The *.xml.builder file does the work of formatting the list of Posts into a Google sitemap compliant file:
Beware, there is a 50,000 URL limit for each sitemap you submit to Google through its indexing service.
Submit Sitemap to Google Automatically
You can also automate your sitemap.xml submissions to Google using this handy Cronjob on Ubuntu or any flavor of linux:
Do pay attention to the /user/bin/curl directive. You must give the absolute path to your instance of curl. Also, I don’t want to handle any responses from Google, so I send any responses to /dev/null. Think of /dev/null as a black hole where data goes in and is never stored or seen again!
Good luck with your next social media venture. And remember to take some time to have fun with it!