[Radiant] Google sitemap.xml support + ActionView helpers in
behaviors?
Jay Levitt
lists-radiant at shopwatch.org
Mon Jul 10 18:10:39 CDT 2006
Xavier wrote:
> Hi folks,
>
> I added a tiny extra chunk of code in my SiteController to generate a
> sitemap.xml file (
> http://www.google.com/support/webmasters/bin/topic.py?topic=8467 )
> from the list of all published pages.
>
> If there's any wider interest for such a feature, I could package it
> as a Behavior.
Definitely. I just did something similar, already set up as a behavior,
but it's hardcoded to my site at the moment, while I tried to figure out
how to get at the full URL..
--
class SiteMapBehavior < Behavior::Base
register "Sitemap"
description %{
Creates a Google sitemap.
}
define_tags do
tag "sitemap" do |tag|
root = Page.find_by_parent_id(nil)
sitemap_header
sitemap_for(root)
sitemap_footer
end
end
private
def sitemap_for(page)
sitemap_url(page.url, page.published_at)
page.children.each do |child|
if child.published? and not child.virtual?
sitemap_for(child)
end
end
end
def sitemap_header
@sitemap = '<?xml version="1.0" encoding="UTF-8"?>' + "\n" +
'<urlset xmlns="http://www.google.com/schemas/sitemap/0.84">' +
"\n"
@sitemap << DummyController.new(self).url_for("/testing")
end
def sitemap_footer
@sitemap << "</urlset>"
end
def sitemap_url(url, published_at)
@sitemap << "<url>\n"
full_url = "http://www.wellesleycarriagehouse.com#{url}"
@sitemap << " <loc>#{full_url}</loc>\n"
if published_at
pub_date = published_at.strftime("%Y-%m-%d")
@sitemap << " <lastmod>#{pub_date}</lastmod>\n"
end
@sitemap << "</url>\n"
end
end
More information about the Radiant
mailing list