Skip to content

Commit

Permalink
Add Google's 'no image preview' meta tag to organisation pages
Browse files Browse the repository at this point in the history
Google sometimes displays organisation pages as a 'rich snippet'. Google decides what image they feature on these search results. As we do not control what image they use, and sometimes the wrong image may be problematic, we can prevent Google showing a preview image on these pages."
  • Loading branch information
AshGDS committed Jan 16, 2024
1 parent 98b3a46 commit 5857230
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/views/organisations/_meta.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<% content_for :meta_tags do %>
<%= tag("meta", name: "description", content: organisation.description) if organisation.description %>
<%= tag("meta", name: "robots", content: "max-image-preview:none") %>
<%= auto_discovery_link_tag(:json, api_organisation_url(organisation.slug), title: organisation.title) %>
<%= auto_discovery_link_tag(:atom, feed_organisation_url(organisation.slug, format: :atom), title: organisation.title) %>
<% end %>
3 changes: 2 additions & 1 deletion spec/features/organisation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,15 @@
expect(page).to have_css(".content")
end

it "includes description and autodiscovery meta tags" do
it "includes description, autodiscovery, and google no image preview meta tags" do
visit "/government/organisations/prime-ministers-office-10-downing-street"
padded_string =
"10 Downing Street is the official residence and the office of the British Prime Minister.\
The office helps the Prime Minister to establish and deliver the government’s overall strategy and policy priorities,\
and to communicate the government’s policies to Parliament, the public and international audiences."
string = padded_string.gsub(" ", " ")
expect(page).to have_selector("meta[name='description'][content='#{string}']", visible: :hidden)
expect(page).to have_selector("meta[name='robots'][content='max-image-preview:none']", visible: :hidden)
expect(page).to have_css("link[rel='alternate'][type='application/json'][href$='/api/organisations/prime-ministers-office-10-downing-street']", visible: :hidden)
expect(page).to have_css("link[rel='alternate'][type='application/atom+xml'][href$='/government/organisations/prime-ministers-office-10-downing-street.atom']", visible: :hidden)
end
Expand Down

0 comments on commit 5857230

Please sign in to comment.