Add sitemap functionality and better documentation

This commit is contained in:
2014-11-05 20:21:57 +01:00
parent 6afc9bdae9
commit b6fec4f880
9 changed files with 323 additions and 228 deletions
+17
View File
@@ -1,6 +1,7 @@
module Cmtool
module Includes
module PagesController
extend ActiveSupport::Concern
def home
page_name = "home"
@page = ::Page.find_by_name_and_locale(page_name, I18n.locale.to_s) || ::Page.new(:name => page_name, locale: I18n.locale.to_s)
@@ -28,6 +29,22 @@ module Cmtool
@sub_pages = []
render template: 'pages/404', layout: @page.layout.presence || ::Page.layouts.first.to_s, status: 404
end
def sitemap
respond_to do |format|
format.xml do
page_uris = ::Page.all.map{|p| page_path(p.name, locale: p.locale)}
pages_xml = page_uris.map{|uri| "<url><loc>#{uri}</loc></url>"}.join("\n")
result = <<-XML
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
#{pages_xml}
</urlset>
XML
render xml: result
end
end
end
end
end
end