Sha256: e74b478bdd8373aa6118731d4dc89ae7e5e07150a0a91944c9deb6aff2944382

Contents?: true

Size: 1.17 KB

Versions: 18

Compression:

Stored size: 1.17 KB

Contents

# frozen_string_literal: true

module PagesCore
  module OpenGraphTagsHelper
    def open_graph_properties
      @open_graph_properties ||= {}
    end

    # Outputs Open Graph tags for Facebook.
    def open_graph_tags
      properties = default_open_graph_properties.merge(open_graph_properties)
      safe_join(
        properties
          .delete_if { |_, content| content.nil? }
          .map do |name, content|
          tag.meta(property: "og:#{name}", content: content)
        end,
        "\n"
      )
    end

    private

    def default_open_graph_title
      if @page.try(:open_graph_title?)
        @page.open_graph_title
      else
        document_title
      end
    end

    def default_open_graph_description
      if @page.try(:open_graph_description?)
        @page.open_graph_description
      elsif meta_description?
        meta_description
      end
    end

    def default_open_graph_properties
      {
        type: "website",
        site_name: PagesCore.config(:site_name),
        title: default_open_graph_title,
        image: (meta_image if meta_image?),
        description: default_open_graph_description,
        url: request.url
      }
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
pages_core-3.12.4 app/helpers/pages_core/open_graph_tags_helper.rb
pages_core-3.12.3 app/helpers/pages_core/open_graph_tags_helper.rb
pages_core-3.12.2 app/helpers/pages_core/open_graph_tags_helper.rb
pages_core-3.12.1 app/helpers/pages_core/open_graph_tags_helper.rb
pages_core-3.12.0 app/helpers/pages_core/open_graph_tags_helper.rb
pages_core-3.11.3 app/helpers/pages_core/open_graph_tags_helper.rb
pages_core-3.11.2 app/helpers/pages_core/open_graph_tags_helper.rb
pages_core-3.11.1 app/helpers/pages_core/open_graph_tags_helper.rb
pages_core-3.11.0 app/helpers/pages_core/open_graph_tags_helper.rb
pages_core-3.10.2 app/helpers/pages_core/open_graph_tags_helper.rb
pages_core-3.10.1 app/helpers/pages_core/open_graph_tags_helper.rb
pages_core-3.9.2 app/helpers/pages_core/open_graph_tags_helper.rb
pages_core-3.9.1 app/helpers/pages_core/open_graph_tags_helper.rb
pages_core-3.9.0 app/helpers/pages_core/open_graph_tags_helper.rb
pages_core-3.8.3 app/helpers/pages_core/open_graph_tags_helper.rb
pages_core-3.8.2 app/helpers/pages_core/open_graph_tags_helper.rb
pages_core-3.8.1 app/helpers/pages_core/open_graph_tags_helper.rb
pages_core-3.8.0 app/helpers/pages_core/open_graph_tags_helper.rb