Sha256: 81eeea51586192c294d17159b42fe9bbb3b85d9024886d31e83da7bf1d0c8411

Contents?: true

Size: 942 Bytes

Versions: 3

Compression:

Stored size: 942 Bytes

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.item_type.title_field
        end

        def item_title
          @item_title ||= seo_field_with_fallback(
            :title,
            title_field && item[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

3 entries across 3 versions & 1 rubygems

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