comfy/comfortable-mexican-sofa — pull request #137 by cbrunsdon (2012-01-24 10:38:33+00:00)
Title: Add the ability to extend sitemaps

Okay, here's the API I went with for extending sitemaps.

My two main goals were:
* Ability to use routes for locations
* Flexibility in defining the sitemap structure

I went with a callback that takes the cms_site, current view, and xml builder reference allowing me to define the structure of the sitemaps wherever I want.

You can register the callbacks in an initializer

ComfortableMexicanSofa::Sitemap.register_extension(
SiteNews.method(:sitemap_callback))

Whose code would be:

def self.sitemap_callback(cms_site, view, xml)
scoped.where(:cms_site_id => cms_site).published.each do |news|
xml.url do
xml.loc view.site_news_url(news)
xml.lastmod news.updated_at.strftime('%Y-%m-%d')
end
end
end

I'm not tied to that API by any stretch, but this seemed to provide the most flexibility. I had some trouble deciding where I wanted to define the sitemap links, but in the end the model seemed to make the most sense.

Side note: sorry if my git's a bit of a mess, I've actually sat down to figure things out rather than muddling through it.