diff --git a/app/presenters/publication_presenter.rb b/app/presenters/publication_presenter.rb index a1595f9a8..f977d890f 100644 --- a/app/presenters/publication_presenter.rb +++ b/app/presenters/publication_presenter.rb @@ -25,4 +25,9 @@ def national_statistics? def dataset? %(national_statistics official_statistics transparency).include? document_type end + + # this is a temporary hack and should be removed in approx 3 months + def hide_from_search_engines? + content_item["base_path"] == "/government/publications/pension-credit-claim-form--2" + end end diff --git a/app/views/content_items/publication.html.erb b/app/views/content_items/publication.html.erb index 8ffbcc9ff..8664712da 100644 --- a/app/views/content_items/publication.html.erb +++ b/app/views/content_items/publication.html.erb @@ -2,6 +2,10 @@ <%= machine_readable_metadata( schema: (@content_item.dataset? ? :dataset : :article) ) %> + + <% if @content_item.hide_from_search_engines? %> + + <% end %> <% end %> <%= render 'shared/email_subscribe_unsubscribe_flash', { title: @content_item.title } %> diff --git a/public/robots.txt b/public/robots.txt index 181e6f3ff..66df018ae 100644 --- a/public/robots.txt +++ b/public/robots.txt @@ -1,5 +1,5 @@ # See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file # # To ban all spiders from the entire site uncomment the next two lines: -# User-agent: * -# Disallow: / +User-agent: * +Disallow: /government/publications/pension-credit-claim-form--2 \ No newline at end of file diff --git a/test/integration/publication_test.rb b/test/integration/publication_test.rb index ad1b80821..d24a88667 100644 --- a/test/integration/publication_test.rb +++ b/test/integration/publication_test.rb @@ -288,4 +288,10 @@ class PublicationTest < ActionDispatch::IntegrationTest setup_and_visit_notification_exempt_page("publication") assert_not page.has_css?(".gem-c-single-page-notification-button") end + + test "adds the noindex meta tag to '/government/publications/pension-credit-claim-form--2'" do + overrides = { "base_path" => "/government/publications/pension-credit-claim-form--2" } + setup_and_visit_content_item("publication-with-featured-attachments", overrides) + assert page.has_css?('meta[name="robots"][content="noindex"]', visible: false) + end end diff --git a/test/presenters/publication_presenter_test.rb b/test/presenters/publication_presenter_test.rb index 94907fdde..7f0f99f34 100644 --- a/test/presenters/publication_presenter_test.rb +++ b/test/presenters/publication_presenter_test.rb @@ -78,4 +78,18 @@ def schema_name presented = presented_item("statistics_publication") assert presented.has_single_page_notifications? end + + test "hide_from_search_engines? returns false" do + presented = presented_item("publication-with-featured-attachments") + + assert_not(presented.hide_from_search_engines?) + end + + test "hide_from_search_engines? returns true if the page is '/government/publications/pension-credit-claim-form--2'" do + schema_example = schema_item("publication-with-featured-attachments") + schema_example["base_path"] = "/government/publications/pension-credit-claim-form--2" + presented = presented_item("publication", schema_example) + + assert presented.hide_from_search_engines? + end end