Sha256: 049e7772f7b9b81aa263fafea518823733e0c27439518355004c540ccd5c07c2

Contents?: true

Size: 855 Bytes

Versions: 3

Compression:

Stored size: 855 Bytes

Contents

# frozen_string_literal: true

require "dato/utils/meta_tags/base"

module Dato
  module Utils
    module MetaTags
      class Image < Base
        def build
          return unless image

          [
            og_tag("og:image", image.url),
            card_tag("twitter:image", image.url),
          ]
        end

        def image
          @image ||= seo_field_with_fallback(:image, item_image)
        end

        def item_image
          item && item.fields
                      .select { |field| field.field_type == "file" }
                      .map { |field| item[field.api_key] }
                      .compact
                      .find do |image|
                        image.width && image.height &&
                          image.width >= 200 && image.height >= 200
                      end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dato-0.8.3 lib/dato/utils/meta_tags/image.rb
dato-0.8.2 lib/dato/utils/meta_tags/image.rb
dato-0.8.1 lib/dato/utils/meta_tags/image.rb