Sha256: c53fe21b8a8409dfaa001d814d8fc0309e2574bae63975367b653bb5a93a617d

Contents?: true

Size: 1.11 KB

Versions: 12

Compression:

Stored size: 1.11 KB

Contents

module OpenGraphHelper
  # OpenGraph is in meta tags. First I thought it would bring problem if meta tags wouldn't change between page load.
  # Thinking it through, it doesn't matter if open graph tags aren't changed between pages as it's needed by crawler that does full page load
  # So the tags will always match the content.
  # I doubt this will change in the future as turbolinks checks for crawlers and disable itself when it meets one.
  #

  def open_graph_tags
    if @post.nil?
      og_website
    else
      og_article(@post)
    end
  end

  protected

  def og_website
    [
      og_title,
      og_type('website')
    ].join.html_safe
  end

  def og_article(post)
    raise OGNoArticleError if post.nil?
    [
      og_title,
      og_type('article'),
      content_tag(:meta, nil, property: 'og:article:published_time', content: post.published_at.iso8601)
    ].join.html_safe

  end

  def og_type(value)
    content_tag :meta, nil, property: 'og:type', content: value
  end

  def og_title
    content_tag :meta, nil, property: 'og:title', content: title
  end

  class OGNoArticleError < StandardError; end

end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
ecrire-0.26.2 lib/ecrire/app/helpers/open_graph_helper.rb
ecrire-0.26.1 lib/ecrire/app/helpers/open_graph_helper.rb
ecrire-0.26.0 lib/ecrire/app/helpers/open_graph_helper.rb
ecrire-0.25.2 lib/ecrire/app/helpers/open_graph_helper.rb
ecrire-0.25.1 lib/ecrire/app/helpers/open_graph_helper.rb
ecrire-0.25.0 lib/ecrire/app/helpers/open_graph_helper.rb
ecrire-0.24.1 lib/ecrire/app/helpers/open_graph_helper.rb
ecrire-0.24.0 lib/ecrire/app/helpers/open_graph_helper.rb
ecrire-0.23.0 lib/ecrire/app/helpers/open_graph_helper.rb
ecrire-0.22.1 lib/ecrire/app/helpers/open_graph_helper.rb
ecrire-0.21.0 lib/ecrire/app/helpers/open_graph_helper.rb
ecrire-0.20.0 lib/ecrire/app/helpers/open_graph_helper.rb