Sha256: 344e187750a5c74ba2eaca0928988ee9e6656c2e51d366cd130e49319b5de870

Contents?: true

Size: 1.12 KB

Versions: 6

Compression:

Stored size: 1.12 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
          .compact
          .map do |name, content|
          tag.meta(property: "og:#{name}", 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&.strip,
        url: request.url }
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
pages_core-3.15.4 app/helpers/pages_core/open_graph_tags_helper.rb
pages_core-3.15.3 app/helpers/pages_core/open_graph_tags_helper.rb
pages_core-3.15.2 app/helpers/pages_core/open_graph_tags_helper.rb
pages_core-3.15.1 app/helpers/pages_core/open_graph_tags_helper.rb
pages_core-3.14.0 app/helpers/pages_core/open_graph_tags_helper.rb
pages_core-3.13.0 app/helpers/pages_core/open_graph_tags_helper.rb