diff --git a/app/controllers/sitemap_controller.rb b/app/controllers/sitemap_controller.rb new file mode 100644 index 00000000..3b5c270c --- /dev/null +++ b/app/controllers/sitemap_controller.rb @@ -0,0 +1,10 @@ +class SitemapController < ApplicationController + layout nil + + def index + respond_to do |format| + format.xml { @items = Item.sitemap } + end + end +end + diff --git a/app/models/item.rb b/app/models/item.rb index 3b17d414..f04ce234 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -40,6 +40,8 @@ class Item < ActiveRecord::Base scope :sold_in_mall, where(:sold_in_mall => true) scope :not_sold_in_mall, where(:sold_in_mall => false) + scope :sitemap, select([:id, :name]).order(:id).limit(49999) + # Not defining validations, since this app is currently read-only def nc? diff --git a/app/views/sitemap/index.xml.haml b/app/views/sitemap/index.xml.haml new file mode 100644 index 00000000..ee110b35 --- /dev/null +++ b/app/views/sitemap/index.xml.haml @@ -0,0 +1,14 @@ +!!! XML +%urlset{:xmlns => "http://www.sitemaps.org/schemas/sitemap/0.9"} + - for item in @items + %url + %loc http://#{request.host_with_port}#{url_for(item)} + %changefreq monthly + %priority 0.5 + + -# Homepage + %url + %loc= root_url + %changefreq monthly + %priority 1.0 + diff --git a/config/routes.rb b/config/routes.rb index 5e464fcc..b5ff9bd0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -41,5 +41,7 @@ OpenneoImpressItems::Application.routes.draw do |map| match '/wardrobe' => 'outfits#edit', :as => :wardrobe match '/terms' => 'static#terms', :as => :terms + + match '/sitemap.xml' => 'sitemap#index', :as => :sitemap, :format => :xml end