Skip to content

Commit

Permalink
Merge pull request #3325 from alphagov/no_index
Browse files Browse the repository at this point in the history
Add a noindex metatag to specific publication
  • Loading branch information
hannako authored Sep 10, 2024
2 parents c84dc30 + c80f0e0 commit d568ad1
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 2 deletions.
5 changes: 5 additions & 0 deletions app/presenters/publication_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions app/views/content_items/publication.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
<%= machine_readable_metadata(
schema: (@content_item.dataset? ? :dataset : :article)
) %>

<% if @content_item.hide_from_search_engines? %>
<meta name="robots" content="noindex">
<% end %>
<% end %>

<%= render 'shared/email_subscribe_unsubscribe_flash', { title: @content_item.title } %>
Expand Down
4 changes: 2 additions & 2 deletions public/robots.txt
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions test/integration/publication_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 14 additions & 0 deletions test/presenters/publication_presenter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit d568ad1

Please sign in to comment.