Skip to content

Commit

Permalink
Merge pull request #905 from alphagov/use-component-structured-data
Browse files Browse the repository at this point in the history
Add schema.org data via the new component
  • Loading branch information
tijmenb authored May 17, 2018
2 parents 1d68f46 + be4ed0f commit dd34445
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 90 deletions.
4 changes: 0 additions & 4 deletions app/presenters/news_article_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,4 @@ class NewsArticlePresenter < ContentItemPresenter
def image
content_item["details"]["image"]
end

def structured_data
NewsArticleStructured.new(self).structured_data
end
end
64 changes: 0 additions & 64 deletions app/presenters/news_article_structured.rb

This file was deleted.

6 changes: 6 additions & 0 deletions app/views/content_items/answer.html.erb
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
<% content_for :extra_head_content do %>
<%= render 'govuk_publishing_components/components/machine_readable_metadata',
schema: :article,
content_item: @content_item.content_item %>
<% end %>

<%= render 'content_items/body_with_related_links' %>
7 changes: 7 additions & 0 deletions app/views/content_items/guide.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
<% content_for :extra_head_content do %>
<%= render 'govuk_publishing_components/components/machine_readable_metadata',
schema: :article,
content_item: @content_item.content_item,
canonical_url: @content_item.canonical_url %>
<% end %>

<% content_for :simple_header, true %>
<div class="grid-row">
<div class="column-two-thirds">
Expand Down
8 changes: 5 additions & 3 deletions app/views/content_items/news_article.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<script type="application/ld+json">
<%= @content_item.structured_data.to_json.html_safe %>
</script>
<% content_for :extra_head_content do %>
<%= render 'govuk_publishing_components/components/machine_readable_metadata',
schema: :news_article,
content_item: @content_item.content_item %>
<% end %>

<div class="grid-row">
<div class="column-two-thirds">
Expand Down
14 changes: 11 additions & 3 deletions app/views/content_items/travel_advice.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
<%
content_for :simple_header, true
content_for :extra_head_content do %>
<% content_for :simple_header, true %>

<% content_for :extra_head_content do %>
<%= auto_discovery_link_tag :atom, @content_item.feed_link,
title: "Recent updates for #{@content_item.country_name}" %>

<%= render 'govuk_publishing_components/components/machine_readable_metadata',
schema: :article,
content_item: @content_item.content_item,
canonical_url: @content_item.canonical_url,
title: @content_item.page_title,
body: @content_item.current_part_body %>
<% end %>

<div class="grid-row">
<div class="column-two-thirds">
<%= render 'govuk_component/title', @content_item.title_and_context %>
Expand Down
16 changes: 0 additions & 16 deletions test/presenters/news_article_presenter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,6 @@ class PresentedNewsArticleTest < NewsArticlePresenterTestCase
test 'presents the locale' do
assert_equal schema_item['locale'], presented_item.locale
end

test 'has no structured data if no publishing org' do
expected = {}
assert_equal expected, presented_item.structured_data
end

test 'has structured data' do
item = { "links" => { "primary_publishing_organisation" => [{ "title" => "Ministry of Magic", "base_path" => "/government/organisations/magic" }] } }

structured_data = presented_item("news_article", item).structured_data

assert_equal "https://www.test.gov.uk/government/news/christmas-2016-prime-ministers-message", structured_data["mainEntityOfPage"]["@id"]
assert_equal "2016-12-25T00:15:02.000+00:00", structured_data["datePublished"]
assert_equal "Ministry of Magic", structured_data["author"]["name"]
assert_equal "https://www.test.gov.uk/government/organisations/magic", structured_data["author"]["url"]
end
end

class HistoryModePresentedNewsArticle < NewsArticlePresenterTestCase
Expand Down

0 comments on commit dd34445

Please sign in to comment.