Skip to content

Commit

Permalink
Add a noindex metatag to specific publication
Browse files Browse the repository at this point in the history
As requested by DWP and senior leadership
This is a temporary fix and should be removed within 3 months
  • Loading branch information
hannako committed Sep 9, 2024
1 parent c84dc30 commit 6a1e1c9
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/presenters/content_item_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ def service_manual_homepage?
false
end

def hide_from_search_engines?
false
end

def render_guide_as_single_page?
# /how-to-vote
content_id == "9315bc67-33e7-42e9-8dea-e022f56dabfa" && voting_is_open?
Expand Down
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
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 6a1e1c9

Please sign in to comment.