diff --git a/app/views/robots/index.text.erb b/app/views/robots/index.text.erb index 5566786d6..70ef9baa2 100644 --- a/app/views/robots/index.text.erb +++ b/app/views/robots/index.text.erb @@ -74,11 +74,32 @@ Allow: /sitemap.xml Allow: /favicon.ico Allow: /favicon.svg +<% if Artist.undeleted.exists? %> Sitemap: <%= sitemap_url(format: :xml, sitemap: "artists") %> +<% end %> + +<% if ForumTopic.undeleted.exists? %> Sitemap: <%= sitemap_url(format: :xml, sitemap: "forum_topics") %> +<% end %> + +<% if Pool.undeleted.exists? %> Sitemap: <%= sitemap_url(format: :xml, sitemap: "pools") %> +<% end %> + +<% if Post.exists? %> Sitemap: <%= sitemap_url(format: :xml, sitemap: "posts") %> +<% end %> + +<% if Tag.nonempty.exists? %> Sitemap: <%= sitemap_url(format: :xml, sitemap: "tags") %> +<% end %> + +<% if User.exists? %> Sitemap: <%= sitemap_url(format: :xml, sitemap: "users") %> +<% end %> + +<% if WikiPage.undeleted.exists? %> Sitemap: <%= sitemap_url(format: :xml, sitemap: "wiki_pages") %> <% end %> + +<% end %> diff --git a/app/views/static/sitemap_index.xml.erb b/app/views/static/sitemap_index.xml.erb index eaae89833..1f9403a3d 100644 --- a/app/views/static/sitemap_index.xml.erb +++ b/app/views/static/sitemap_index.xml.erb @@ -1,7 +1,7 @@ - <% 0.upto(@relation.maximum(:id) / @limit) do |page| %> + <% 0.upto(@relation.maximum(:id).to_i / @limit) do |page| %> <% lo = page * @limit %> <% hi = (page + 1) * @limit %> <% lastmod = @relation.where(id: lo..hi).maximum(:updated_at)&.iso8601 %> diff --git a/test/functional/static_controller_test.rb b/test/functional/static_controller_test.rb index 1cda87527..324cd953c 100644 --- a/test/functional/static_controller_test.rb +++ b/test/functional/static_controller_test.rb @@ -23,6 +23,12 @@ class StaticControllerTest < ActionDispatch::IntegrationTest assert_equal(1, response.parsed_body.css("sitemap loc").size) end end + + should "work when the sitemap is empty" do + get sitemap_path(sitemap: "pools"), as: :xml + + assert_response :success + end end context "dtext_help action" do