Skip to content

Instantly share code, notes, and snippets.

@techarch
Created March 13, 2010 00:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save techarch/330973 to your computer and use it in GitHub Desktop.
Save techarch/330973 to your computer and use it in GitHub Desktop.
module MyApp::Controllers
class Test1 < R '/test1'
end
class Test2 < R '/test2'
end
SITE_BASE_URL = "http://www.myapp.com"
# --- --- ---
def self.sitemap_candidates
[ :Test1, :Test2 ]
end
class GoogleSiteMap < R '/sitemap.xml'
def get
@headers['Content-Type'] = "application/xml"
sitemap_xml = Builder::XmlMarkup.new(:indent=>2)
sitemap_xml.instruct!(:xml, :encoding => "UTF-8")
sitemap_xml.urlset 'xmlns:xsi'.to_sym=> "http://www.w3.org/2001/XMLSchema-instance" ,
'xsi:schemaLocation'.to_sym=>"http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" ,
:xmlns=>"http://www.sitemaps.org/schemas/sitemap/0.9" do
sitemap_xml.url do
sitemap_xml.loc "#{SITE_BASE_URL}/"
sitemap_xml.lastmod Time.now.utc.strftime('%Y-%m-%dT%H:%M:%S+00:00')
sitemap_xml.changefreq "daily"
sitemap_xml.priority "1.0"
end
MyApp::Controllers.sitemap_candidates.each do | c |
k = MyApp::Controllers.const_get c
if (k.respond_to? :urls) && !k.urls.empty? && !(k.urls[0].match(/[ \[ | \( ]/))
sitemap_xml.url do
sitemap_xml.loc "#{SITE_BASE_URL}#{k.urls[0]}"
sitemap_xml.lastmod Time.now.utc.strftime('%Y-%m-%dT%H:%M:%S+00:00')
sitemap_xml.changefreq "weekly"
sitemap_xml.priority "0.8"
end
end
end
end
@headers['X-Sendfile'] = sitemap_xml.target!
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment