Sha256: 050d93a487eb15092a76372371a037c3c4bf2376a1b0aa6f5ef120dec5e8dc5f
Contents?: true
Size: 1.09 KB
Versions: 2
Compression:
Stored size: 1.09 KB
Contents
module Sitemap extend ActiveSupport::Concern def render_sitemap(allowed_locales = nil) allowed_locales ||= I18n.available_locales.map(&:to_s) @pages = Page.where("locale IN (?)", allowed_locales).sort do |p1, p2| (p1.path || "").split("/").size <=> (p2.path || "").split("/").size end erb = <<-eos <?xml version="1.0" encoding="UTF-8"?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <% @pages.each do |page| -%> <% if !page.resourceful? -%> <% begin -%> <% loc = polymorphic_url([:site, page.uid.split("#").last, page.locale].compact) -%> <url> <loc><%= loc %></loc> </url> <% rescue Exception => e -%> <% end -%> <% else -%> <% page.resource_class.where(:locale => page.locale).each do |resource| -%> <url> <loc><%= page_url_for(resource) -%></loc> <% if resource.respond_to?(:updated_at) -%> <lastmod><%= resource.updated_at.strftime("%F") -%></lastmod> <% end -%> </url> <% end -%> <% end -%> <% end -%> </urlset> eos render :inline => erb, :layout => false end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
fullstack-cms-0.3.15 | app/support/sitemap.rb |
fullstack-cms-0.3.14 | app/support/sitemap.rb |