module Cdx::ControllerHelpers::Seo

Public Instance Methods

canonical_url() click to toggle source
# File lib/cdx/controller_helpers/seo.rb, line 16
def canonical_url
  # Override this methods in your controllers to get a custom canonical_url
  request.fullpath
end
contextual_record() click to toggle source
# File lib/cdx/controller_helpers/seo.rb, line 21
def contextual_record
  # Override this methods in your controllers to get seo data from a specific record
  instance_variable_get("@#{controller_name.singularize}") || @object || Setting.current
end
meta_data() click to toggle source
# File lib/cdx/controller_helpers/seo.rb, line 26
def meta_data
  # Override this methods in your controllers to get custom SEO data
  object = contextual_record
  fields = {}

  if object.respond_to? :seo
    fields[:keywords]    = object.meta_keywords || Setting.current.meta_keywords
    fields[:description] = object.meta_description || Setting.current.meta_description
  end
  fields.reject { |k, v| v.blank? }
end
meta_title() click to toggle source
# File lib/cdx/controller_helpers/seo.rb, line 11
def meta_title
  # Override this methods in your controllers to get a custom title
  contextual_record.meta_title
end
open_graph_data() click to toggle source
# File lib/cdx/controller_helpers/seo.rb, line 38
def open_graph_data
  # Override this methods in your controllers to get custom OpenGraph data
  object = contextual_record
  fields = {}

  if object.respond_to? :seo
    fields['og:title']       = object.og_title || Setting.current.og_title
    fields['og:description'] = object.og_description || Setting.current.og_description
    fields['og:keywords']    = object.og_keywords || Setting.current.og_keywords
    fields['og:image']       = object.og_image&.attachment&.url(:regular) || Setting.current.og_image&.attachment&.url(:regular)
    fields['og:video']       = object.og_video || Setting.current.og_video
  end
  fields.reject { |k, v| v.blank? }
end