Sha256: 60c261d12f749871e216314d1767c5365b36f484dbed11569c84659c62d34725

Contents?: true

Size: 1.03 KB

Versions: 44

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true
require 'dato/utils/meta_tags/base'

module Dato
  module Utils
    module MetaTags
      class Title < Base
        def build
          return unless item_title

          [
            content_tag('title', item_title_with_suffix),
            og_tag('og:title', item_title),
            card_tag('twitter:title', item_title)
          ]
        end

        def title_field
          item && item.fields.find do |field|
            field.field_type == 'string' &&
              field.appeareance[:type] == 'title'
          end
        end

        def item_title
          @item_title ||= seo_field_with_fallback(
            :title,
            title_field && item.send(title_field.api_key)
          )
        end

        def suffix
          (site.global_seo && site.global_seo.title_suffix) || ''
        end

        def item_title_with_suffix
          if (item_title + suffix).size <= 60
            item_title + suffix
          else
            item_title
          end
        end
      end
    end
  end
end

Version data entries

44 entries across 44 versions & 1 rubygems

Version Path
dato-0.3.23 lib/dato/utils/meta_tags/title.rb
dato-0.3.22 lib/dato/utils/meta_tags/title.rb
dato-0.3.21 lib/dato/utils/meta_tags/title.rb
dato-0.3.20 lib/dato/utils/meta_tags/title.rb
dato-0.3.19 lib/dato/utils/meta_tags/title.rb
dato-0.3.18 lib/dato/utils/meta_tags/title.rb
dato-0.3.17 lib/dato/utils/meta_tags/title.rb
dato-0.3.16 lib/dato/utils/meta_tags/title.rb
dato-0.3.15 lib/dato/utils/meta_tags/title.rb
dato-0.3.14 lib/dato/utils/meta_tags/title.rb
dato-0.3.13 lib/dato/utils/meta_tags/title.rb
dato-0.3.12 lib/dato/utils/meta_tags/title.rb
dato-0.3.9.1 lib/dato/utils/meta_tags/title.rb
dato-0.3.11 lib/dato/utils/meta_tags/title.rb
dato-0.3.10 lib/dato/utils/meta_tags/title.rb
dato-0.3.9 lib/dato/utils/meta_tags/title.rb
dato-0.3.8 lib/dato/utils/meta_tags/title.rb
dato-0.3.7 lib/dato/utils/meta_tags/title.rb
dato-0.3.6 lib/dato/utils/meta_tags/title.rb
dato-0.3.5 lib/dato/utils/meta_tags/title.rb