do not include redirect page in the sitemap

did committed Mar 16, 2017
commit 0e5acc1172333421d476f8ad3473f4f457c04c5f
Showing 5 changed files with 37 additions and 3 deletions
locomotive/steam/entities/page.rb b/lib/locomotive/steam/entities/page.rb +1 -0
@@ @@ -33,6 +33,7 @@ module Locomotive::Steam
def listed?; !!listed; end
def published?; !!published; end
def templatized?; !!templatized; end
+ def redirect?; redirect.nil? ? !redirect_url.blank? : redirect; end
def content_type_id
self.target_klass_name =~ Locomotive::Steam::CONTENT_ENTRY_ENGINE_CLASS_NAME
locomotive/steam/middlewares/sitemap.rb b/lib/locomotive/steam/middlewares/sitemap.rb +9 -1
@@ @@ -28,7 +28,7 @@ module Locomotive::Steam
def build_pages_to_xml
page_repository.published.map do |page|
- next if page.index? || page.not_found? || page.layout? || (!page.templatized? && !page.listed?)
+ next if skip_page?(page)
build_page_xml(page)
end.flatten.join.strip
@@ @@ -80,6 +80,14 @@ module Locomotive::Steam
EOF
end
+ def skip_page?(page)
+ page.index? ||
+ page.not_found? ||
+ page.layout? ||
+ page.redirect? ||
+ (!page.templatized? && !page.listed?)
+ end
+
def repositories
services.repositories
end
locomotive/steam/models/i18n_field.rb b/lib/locomotive/steam/models/i18n_field.rb +2 -1
@@ @@ -40,7 +40,8 @@ module Locomotive::Steam
end
def blank?
- @translations.blank? && @translations[:anything].blank?
+ @translations.blank? ||
+ @translations.values.all? { |v| v.blank? }
end
def apply(&block)
spec/integration/server/sitemap_spec.rb +1 -1
@@ @@ -21,7 +21,7 @@ describe Locomotive::Steam::Server do
it 'checks if it looks valid' do
expect(Nokogiri::XML(subject).errors.empty?).to eq true
- expect(subject.scan(/<url>/).size).to eq 27
+ expect(subject.scan(/<url>/).size).to eq 25
expect(subject).to match("<loc>http://example.org/songs/song-number-2/band</loc>")
expect(subject).to match((<<-EOF
<url>
spec/unit/entities/page_spec.rb +24 -0
@@ @@ -82,4 +82,28 @@ describe Locomotive::Steam::Page do
end
+ describe '#redirect?' do
+
+ subject { page.redirect? }
+
+ it { is_expected.to eq false }
+
+ context 'redirect_url has been set' do
+
+ let(:attributes) { { redirect: nil, redirect_url: 'http://www.google.fr' } }
+
+ it { is_expected.to eq true }
+
+ context 'but redirect is set to false' do
+
+ let(:attributes) { { redirect: false, redirect_url: 'http://www.google.fr' } }
+
+ it { is_expected.to eq false }
+
+ end
+
+ end
+
+ end
+
end