class GovukPublishingComponents::Presenters::ArticleSchema

Attributes

page[R]

Public Class Methods

new(page) click to toggle source
# File lib/govuk_publishing_components/presenters/machine_readable/article_schema.rb, line 6
def initialize(page)
  @page = page
end

Public Instance Methods

structured_data() click to toggle source
# File lib/govuk_publishing_components/presenters/machine_readable/article_schema.rb, line 10
def structured_data
  # http://schema.org/Article
  data = CreativeWorkSchema.new(@page).structured_data
    .merge(head_line)
    .merge(body)
    .merge(search_action)
  data["@type"] = "Article"
  data
end

Private Instance Methods

body() click to toggle source

Not all formats have a `body` - some have their content split over multiple fields. In this case we'll skip the `articleBody` field

# File lib/govuk_publishing_components/presenters/machine_readable/article_schema.rb, line 31
def body
  return {} unless page.body.present?

  {
    "articleBody" => page.body,
  }
end
head_line() click to toggle source
# File lib/govuk_publishing_components/presenters/machine_readable/article_schema.rb, line 22
def head_line
  {
    "headLine" => page.title,
    "description" => page.description,
  }
end
search_action() click to toggle source
# File lib/govuk_publishing_components/presenters/machine_readable/article_schema.rb, line 39
def search_action
  return {} unless page.document_type == "manual"

  manuals_facet_params = { manual: page.base_path }
  PotentialSearchActionSchema.new(manuals_facet_params, search_description).structured_data
end
search_description() click to toggle source
# File lib/govuk_publishing_components/presenters/machine_readable/article_schema.rb, line 46
def search_description
  I18n.t(:scoped_search_description, scope: %i[components article_schema], title: page.title)
end