diff --git a/app/presenters/news_article_presenter.rb b/app/presenters/news_article_presenter.rb index 72e2316f1..b9507ed38 100644 --- a/app/presenters/news_article_presenter.rb +++ b/app/presenters/news_article_presenter.rb @@ -10,8 +10,4 @@ class NewsArticlePresenter < ContentItemPresenter def image content_item["details"]["image"] end - - def structured_data - NewsArticleStructured.new(self).structured_data - end end diff --git a/app/presenters/news_article_structured.rb b/app/presenters/news_article_structured.rb deleted file mode 100644 index d3c9c61e4..000000000 --- a/app/presenters/news_article_structured.rb +++ /dev/null @@ -1,64 +0,0 @@ -class NewsArticleStructured - def initialize(presenter) - @presenter = presenter - end - - def structured_data - return {} unless enough_structured_data? - - # http://schema.org/NewsArticle - { - "@context" => "http://schema.org", - "@type" => "NewsArticle", - "mainEntityOfPage" => { - "@type" => "WebPage", - "@id" => page_url, - }, - "headline" => presenter.title, - "datePublished" => presenter.first_public_at, - "dateModified" => presenter.public_updated_at, - "description" => presenter.description, - "publisher" => { - "@type" => "Organization", - "name" => "GOV.UK", - "url" => "https://www.gov.uk", - "logo" => { - "@type" => "ImageObject", - # TODO: change this to a better image, without the URL hard coded. - "url" => "https://assets.publishing.service.gov.uk/static/opengraph-image-a1f7d89ffd0782738b1aeb0da37842d8bd0addbd724b8e58c3edbc7287cc11de.png", - }, - }, - "image" => [ - image["url"], - ], - "author" => { - "@type" => "Organization", - "name" => publishing_organisation["title"], - "url" => Plek.current.website_root + publishing_organisation["base_path"], - }, - } - end - -private - - attr_reader :presenter - - def enough_structured_data? - # The author (for which we use the publishing org) and image are required - # fields. If the news article doesn't have them, don't use structured data - # at all. - publishing_organisation && image - end - - def publishing_organisation - presenter.content_item.dig("links", "primary_publishing_organisation").to_a.first - end - - def page_url - Plek.current.website_root + presenter.content_item["base_path"] - end - - def image - presenter.image - end -end diff --git a/app/views/content_items/answer.html.erb b/app/views/content_items/answer.html.erb index 24ee37dea..cf9e7615d 100644 --- a/app/views/content_items/answer.html.erb +++ b/app/views/content_items/answer.html.erb @@ -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' %> diff --git a/app/views/content_items/guide.html.erb b/app/views/content_items/guide.html.erb index d0c4f5d34..2a74b31fe 100644 --- a/app/views/content_items/guide.html.erb +++ b/app/views/content_items/guide.html.erb @@ -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 %>