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.6.3 lib/dato/utils/meta_tags/title.rb
dato-0.6.3.beta lib/dato/utils/meta_tags/title.rb
dato-0.6.2 lib/dato/utils/meta_tags/title.rb
dato-0.6.1 lib/dato/utils/meta_tags/title.rb
dato-0.6.0 lib/dato/utils/meta_tags/title.rb
dato-0.5.1 lib/dato/utils/meta_tags/title.rb
dato-0.5.0 lib/dato/utils/meta_tags/title.rb
dato-0.4.3 lib/dato/utils/meta_tags/title.rb
dato-0.4.2 lib/dato/utils/meta_tags/title.rb
dato-0.4.1 lib/dato/utils/meta_tags/title.rb
dato-0.4.0 lib/dato/utils/meta_tags/title.rb
dato-0.3.31 lib/dato/utils/meta_tags/title.rb
dato-0.4.0.pre lib/dato/utils/meta_tags/title.rb
dato-0.3.30 lib/dato/utils/meta_tags/title.rb
dato-0.3.29 lib/dato/utils/meta_tags/title.rb
dato-0.3.28 lib/dato/utils/meta_tags/title.rb
dato-0.3.27 lib/dato/utils/meta_tags/title.rb
dato-0.3.26 lib/dato/utils/meta_tags/title.rb
dato-0.3.25 lib/dato/utils/meta_tags/title.rb
dato-0.3.24 lib/dato/utils/meta_tags/title.rb