After posting blog entries I like to log into my Google Webmaster Tools and force a re-download of my site map to cut down on the time it takes to be indexed. Normally this is a manual process, but it is pretty simple to automate. I develop with Ruby on Rails and host on a Linux server but the same strategy could easily be applied to other environments.
Make sure curl is installed on your app server:
sudo apt-get install curl
Edit your model:
class Post < ActiveRecord::Base
include ActionController::UrlWriter
ActionController::UrlWriter.default_url_options[:host] = 'caffeinefueled.com'
after_create :pimp
private
def pimp
google = "curl -G -d sitemap=\"#{ sitemap_url }\" www.google.com/webmasters/tools/ping"
if RAILS_ENV == 'production'
`#{ google }`
else
logger.debug 'Skipping pimpage because we are not in production!'
logger.debug "[skipping] #{ google }"
end
end
end
Normally you can't use named routes (posts_url, sitemap_url, etc) within your models. I had to include the UrlWriter module and configure the host to get around this. Next I use an Active Record callback to detect the creation of new blog posts. Taking a look at the actual function you can see that I use curl to perform a HTTP get informing Google that I have new content. Generally speaking you should only ping them at most once per hour so you may want to add some logic to prevent flooding them if you post frequently.
This same strategy can be used to promote your content all over the web. You could update your twitter feed or save the content on the various social / bookmarking sites. More on this in future updates.
5 Comments
Nice. Why not wrap this up as a plugin?
@Alistair - definitely a possibility in the future. I would like to add twitter support and maybe a few other bells and whistles before extracting it out.
Why not use the Net::HTTP library to eliminate the dependency on curl?
@Cody - Good call, that would probably be the better way to go for simplicity / cross platform support. This was just a quick hack I through together in 5 minutes. Right now I've got it setup to spawn background curls that ping Ask, Google, Microsoft, Yahoo and update my twitter status. I'll probably extract it out into a plugin in the next week or so when I get some free time.
it could potentially create some noisy test/development logs.
# Pimp could be re-written as, if using curl
def pimp
`curl -G -d sitemap=\"#{ sitemap_url }\" www.google.com/webmasters/tools/ping` unless RAILS_ENV !== 'production'
end