ChrisCodes.com

Rails plugin with Rake task to generate a sitemap.xml

Here's my new Rails plugin consisting of a rake task that will crawl your site and generate a sitemap.xml file.

From the README...

== Generate Sitemap Rake Task

This is a Rails plugin that consists of a rake task generate a sitemap.xml
The task crawls a domain (default is localhost:3000) for all it's url's, 
then builds the sitemap.xml file in public.

Since this simply crawls a domain for url's, this could be used to generate 
sitemaps for any site, not just a Rails application


== Requirements

Both of these are available via RubyGems
Hpricot - http://code.whytheluckystiff.net/hpricot/
Builder - http://rubyforge.org/projects/builder/


== Installation

Any of the typical plugin installation methods will work.

	script/plugin install svn://chriscodes.homelinux.org/rails_plugins/generate_sitemap

or add a svn:externals entry to vendor/plugins

	script/plugin install -x svn://chriscodes.homelinux.org/rails_plugins/generate_sitemap

or from inside your vendor/plugins directory

	svn co svn://chriscodes.homelinux.org/rails_plugins/generate_sitemap generate_sitemap


== Configuration/Usage

Open tasks/generate_sitemap.rake and set the DOMAIN constant to your domain
(DOMAIN is set to localhost:3000 by default, and will use that in the sitemap urls)

You can optionally set the changefreq element, or add the other available 
elements in the building of the xml. (http://www.sitemaps.org/protocol.php)
I haven't devised a way to set this dynamically, as most pages will vary.

Run the task with the command
	rake plugin:generate_sitemap
	
Go to http://localhost:3000/sitemap.xml (or open public/sitemap.xml)


== TODO

 - set changefreq, lastmod, priority dynamically during generation
 - allow generation of sitemap index files
 - write tests
 - allow for exclusions to be specified in an array


== More Info

http://www.sitemaps.org/protocol.php

Questions, comments, patches, etc. can be sent to 
	chris AT chriscodes DOT com


Chris keyed this in on: 2007-04-30
Filed in: Rails, Rails Plugins, Rake, Ruby

Feed Icon

Copyright © 2009 Chris Martin