From f7926753520d8998c9e354198fd25c38691083a5 Mon Sep 17 00:00:00 2001 From: Jessica Jones Date: Mon, 9 Sep 2024 21:18:52 +0100 Subject: [PATCH 1/2] Add a noindex metatag to specific publication As requested by DWP and senior leadership This is a temporary fix and should be removed within 3 months --- app/presenters/publication_presenter.rb | 5 +++++ app/views/content_items/publication.html.erb | 4 ++++ test/integration/publication_test.rb | 6 ++++++ test/presenters/publication_presenter_test.rb | 14 ++++++++++++++ 4 files changed, 29 insertions(+) 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/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 From c80f0e01fce847d58c5bb02780cf36e933e2df54 Mon Sep 17 00:00:00 2001 From: Jessica Jones Date: Mon, 9 Sep 2024 21:22:47 +0100 Subject: [PATCH 2/2] Prevent page from being crawled As per http://www.robotstxt.org/robotstxt.html --- public/robots.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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