Class: Dato::Utils::MetaTags::Image

Inherits:
Base
  • Object
show all
Defined in:
lib/dato/utils/meta_tags/image.rb

Instance Attribute Summary

Attributes inherited from Base

#item, #site

Instance Method Summary collapse

Methods inherited from Base

#card_tag, #content_tag, #initialize, #meta_tag, #og_tag, #seo_field_with_fallback, #tag

Constructor Details

This class inherits a constructor from Dato::Utils::MetaTags::Base

Instance Method Details

#buildObject



9
10
11
12
13
14
15
16
# File 'lib/dato/utils/meta_tags/image.rb', line 9

def build
  return unless image

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

#imageObject



18
19
20
# File 'lib/dato/utils/meta_tags/image.rb', line 18

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

#item_imageObject



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/dato/utils/meta_tags/image.rb', line 22

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