Sha256: 8e1cf141779014c259c657b3029b1a7fd708462e82b8a1bf6db274a79246feb6

Contents?: true

Size: 1.22 KB

Versions: 13

Compression:

Stored size: 1.22 KB

Contents

module GovukPublishingComponents
  module Presenters
    class ArticleSchema
      attr_reader :page

      def initialize(page)
        @page = page
      end

      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

      def head_line
        {
          "headLine" => page.title,
          "description" => page.description,
        }
      end

      # Not all formats have a `body` - some have their content split over
      # multiple fields. In this case we'll skip the `articleBody` field
      def body
        return {} unless page.body.present?

        {
          "articleBody" => page.body,
        }
      end

      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

      def search_description
        I18n.t(:scoped_search_description, scope: %i(components article_schema), title: page.title)
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
govuk_publishing_components-21.42.0 lib/govuk_publishing_components/presenters/machine_readable/article_schema.rb
govuk_publishing_components-21.41.4 lib/govuk_publishing_components/presenters/machine_readable/article_schema.rb
govuk_publishing_components-21.41.3 lib/govuk_publishing_components/presenters/machine_readable/article_schema.rb
govuk_publishing_components-21.41.2 lib/govuk_publishing_components/presenters/machine_readable/article_schema.rb
govuk_publishing_components-21.41.1 lib/govuk_publishing_components/presenters/machine_readable/article_schema.rb
govuk_publishing_components-21.41.0 lib/govuk_publishing_components/presenters/machine_readable/article_schema.rb
govuk_publishing_components-21.40.0 lib/govuk_publishing_components/presenters/machine_readable/article_schema.rb
govuk_publishing_components-21.39.0 lib/govuk_publishing_components/presenters/machine_readable/article_schema.rb
govuk_publishing_components-21.38.5 lib/govuk_publishing_components/presenters/machine_readable/article_schema.rb
govuk_publishing_components-21.38.4 lib/govuk_publishing_components/presenters/machine_readable/article_schema.rb
govuk_publishing_components-21.38.3 lib/govuk_publishing_components/presenters/machine_readable/article_schema.rb
govuk_publishing_components-21.38.2 lib/govuk_publishing_components/presenters/machine_readable/article_schema.rb
govuk_publishing_components-21.38.1 lib/govuk_publishing_components/presenters/machine_readable/article_schema.rb