forked from saurabh/orbit4-5
38 lines
1.3 KiB
Ruby
38 lines
1.3 KiB
Ruby
class SitemapsController < ApplicationController
|
|
def index
|
|
if $mobile.blank?
|
|
pages = Page.root.child_pages_enabled_for_sitemap
|
|
else
|
|
pages = Page.root.child_pages_enabled_for_sitemap_for_mobile
|
|
end
|
|
def create_json(pages)
|
|
item = {}
|
|
pages.each do |page|
|
|
if page.child_page.size > 0
|
|
if page.page_type == "page"
|
|
if $mobile.blank?
|
|
item["#{page.name}"] = {"url"=> "/#{locale.to_s}" + page.url, "children"=>create_json(page.sorted_published_child_pages), "target"=>"_self"}
|
|
else
|
|
item["#{page.name}"] = {"url"=> "/#{locale.to_s}" + page.url, "children"=>create_json(page.sorted_published_child_pages_for_mobile), "target"=>"_self"}
|
|
end
|
|
else
|
|
if $mobile.blank?
|
|
item["#{page.name}"] = {"url"=> page.external_url, "children"=>create_json(page.sorted_published_child_pages), "target"=>"_blank"}
|
|
else
|
|
item["#{page.name}"] = {"url"=> page.external_url, "children"=>create_json(page.sorted_published_child_pages_for_mobile), "target"=>"_blank"}
|
|
end
|
|
end
|
|
else
|
|
if page.page_type == "page"
|
|
item["#{page.name}"] = {"url"=> "/#{locale.to_s}" + page.url, "target"=>"_self"}
|
|
else
|
|
item["#{page.name}"] = {"url"=> page.external_url, "target"=>"_blank"}
|
|
end
|
|
end
|
|
end
|
|
item
|
|
end
|
|
items = create_json(pages)
|
|
items
|
|
end
|
|
end |