Sha256: 4ac489538cd97ae780a4b635094e92589044e34aad8ea12b4ea9a51bff7f9ab8

Contents?: true

Size: 1.07 KB

Versions: 101

Compression:

Stored size: 1.07 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(body)
          .merge(search_action)
        data["@type"] = "Article"
        data
      end

    private

      # 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

101 entries across 101 versions & 1 rubygems

Version Path
govuk_publishing_components-21.27.1 lib/govuk_publishing_components/presenters/machine_readable/article_schema.rb
govuk_publishing_components-21.27.0 lib/govuk_publishing_components/presenters/machine_readable/article_schema.rb
govuk_publishing_components-21.26.2 lib/govuk_publishing_components/presenters/machine_readable/article_schema.rb
govuk_publishing_components-21.26.1 lib/govuk_publishing_components/presenters/machine_readable/article_schema.rb
govuk_publishing_components-21.26.0 lib/govuk_publishing_components/presenters/machine_readable/article_schema.rb
govuk_publishing_components-21.25.0 lib/govuk_publishing_components/presenters/machine_readable/article_schema.rb
govuk_publishing_components-21.24.0 lib/govuk_publishing_components/presenters/machine_readable/article_schema.rb
govuk_publishing_components-21.23.1 lib/govuk_publishing_components/presenters/machine_readable/article_schema.rb
govuk_publishing_components-21.23.0 lib/govuk_publishing_components/presenters/machine_readable/article_schema.rb
govuk_publishing_components-21.22.2 lib/govuk_publishing_components/presenters/machine_readable/article_schema.rb
govuk_publishing_components-21.22.1 lib/govuk_publishing_components/presenters/machine_readable/article_schema.rb
govuk_publishing_components-21.22.0 lib/govuk_publishing_components/presenters/machine_readable/article_schema.rb
govuk_publishing_components-21.21.3 lib/govuk_publishing_components/presenters/machine_readable/article_schema.rb
govuk_publishing_components-21.21.2 lib/govuk_publishing_components/presenters/machine_readable/article_schema.rb
govuk_publishing_components-21.21.1 lib/govuk_publishing_components/presenters/machine_readable/article_schema.rb
govuk_publishing_components-21.21.0 lib/govuk_publishing_components/presenters/machine_readable/article_schema.rb
govuk_publishing_components-21.20.0 lib/govuk_publishing_components/presenters/machine_readable/article_schema.rb
govuk_publishing_components-21.19.1 lib/govuk_publishing_components/presenters/machine_readable/article_schema.rb
govuk_publishing_components-21.19.0 lib/govuk_publishing_components/presenters/machine_readable/article_schema.rb
govuk_publishing_components-21.18.0 lib/govuk_publishing_components/presenters/machine_readable/article_schema.rb