mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-06 02:51:34 +00:00
#1027: Add sitemap.xml generation
This commit is contained in:
11
app/controllers/sitemap_controller.rb
Normal file
11
app/controllers/sitemap_controller.rb
Normal file
@@ -0,0 +1,11 @@
|
||||
class SitemapController < ApplicationController
|
||||
layout nil
|
||||
|
||||
def index
|
||||
headers['Content-Type'] = 'application/xml'
|
||||
@pages = ['shops', 'map', 'producers', 'groups']
|
||||
@enterprises = Enterprise.is_hub
|
||||
@groups = EnterpriseGroup.all
|
||||
respond_to :xml
|
||||
end
|
||||
end
|
||||
18
app/views/sitemap/index.xml.haml
Normal file
18
app/views/sitemap/index.xml.haml
Normal file
@@ -0,0 +1,18 @@
|
||||
!!! XML
|
||||
%urlset{xmlns: "http://www.sitemaps.org/schemas/sitemap/0.9"}
|
||||
- for page in @pages
|
||||
%url
|
||||
%loc= root_url + page
|
||||
%changefreq monthly
|
||||
|
||||
- for enterprise in @enterprises
|
||||
%url
|
||||
%loc= enterprise_shop_url(enterprise)
|
||||
%lastmod= enterprise.updated_at.strftime('%Y-%m-%d')
|
||||
%changefreq weekly
|
||||
|
||||
- for group in @groups
|
||||
%url
|
||||
%loc= group_url(group)
|
||||
%lastmod= enterprise.updated_at.strftime('%Y-%m-%d')
|
||||
%changefreq yearly
|
||||
@@ -169,6 +169,8 @@ Openfoodnetwork::Application.routes.draw do
|
||||
end
|
||||
end
|
||||
|
||||
get 'sitemap.xml', to: 'sitemap#index', defaults: { format: 'xml' }
|
||||
|
||||
# Mount Spree's routes
|
||||
mount Spree::Core::Engine, :at => '/'
|
||||
|
||||
|
||||
12
spec/features/consumer/sitemap_spec.rb
Normal file
12
spec/features/consumer/sitemap_spec.rb
Normal file
@@ -0,0 +1,12 @@
|
||||
require 'spec_helper'
|
||||
|
||||
feature 'sitemap' do
|
||||
let(:enterprise) { create(:distributor_enterprise) }
|
||||
let!(:group) { create(:enterprise_group, enterprises: [enterprise], on_front_page: true) }
|
||||
|
||||
it "renders sitemap" do
|
||||
visit '/sitemap.xml'
|
||||
expect(page).to have_content enterprise_shop_url(enterprise)
|
||||
expect(page).to have_content group_url(group)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user