module FiSeo::ActsAsSeoableInstanceMethods

Public Instance Methods

canonical_url() click to toggle source
# File lib/fi_seo.rb, line 187
def canonical_url
  FiSeo.initialized_config.default_canonical_url
end
create_dynamic_seo_record() click to toggle source
# File lib/fi_seo.rb, line 150
def create_dynamic_seo_record
  DynamicSeo.create(seoable_type: self.class.to_s, seoable_id: id, title: self.title_value,
                    description: self.description_value, keywords: self.keywords_value)
end
description_value() click to toggle source
# File lib/fi_seo.rb, line 199
def description_value
  if self&.dynamic_seo&.description
    self.dynamic_seo.description
  else
    self.send(self.class.seoable_fields.second) || ''
  end
end
facebook_tags() click to toggle source
# File lib/fi_seo.rb, line 167
def facebook_tags
  {
    title: FiSeo.initialized_config.default_facebook_title,
    type: FiSeo.initialized_config.default_facebook_type,
    url: FiSeo.initialized_config.default_facebook_url,
    image: FiSeo.initialized_config.default_facebook_image,
    description: FiSeo.initialized_config.default_facebook_description
  }
end
keywords_value() click to toggle source
# File lib/fi_seo.rb, line 207
def keywords_value
  if self&.dynamic_seo&.keywords
    self.dynamic_seo.keywords
  else
    self.send(self.class.seoable_fields.third) || ''
  end
end
title_value() click to toggle source
# File lib/fi_seo.rb, line 191
def title_value
  if self&.dynamic_seo&.title
    self.dynamic_seo.title
  else
    self.send(self.class.seoable_fields.first) || ''
  end
end
to_meta_tags() click to toggle source
# File lib/fi_seo.rb, line 114
def to_meta_tags
  row = DynamicSeo.find_by_seoable_type_and_seoable_id(self.class.to_s, self.id)
  if row.nil?
    {}
  else
    hash = {
      title: row.title,
      description: row.description,
      keywords: row.keywords,
      lowercase: self.class.seoable_options[:lowercase],
      reverse: self.class.seoable_options[:reverse],
      index: self.class.seoable_options[:index],
      noindex: self.class.seoable_options[:noindex],
      follow: self.class.seoable_options[:follow],
      nofollow: self.class.seoable_options[:nofollow],
      noarchive: self.class.seoable_options[:noarchive],
      separator: self.class.seoable_options[:separator].html_safe
    }

    if self.class.seoable_options[:social].present?
      if self.class.seoable_options[:social].include? :facebook
        hash.merge!(og: facebook_tags)
      end
      if self.class.seoable_options[:social].include? :twitter
        hash.merge!(twitter: twitter_tags)
      end
    end
    if self.class.seoable_options[:canonical].present?
      hash.merge!(canonical: canonical_url)
    end
    hash
  end
end
twitter_tags() click to toggle source
# File lib/fi_seo.rb, line 177
def twitter_tags
  {
    title: FiSeo.initialized_config.default_twitter_title,
    card: FiSeo.initialized_config.default_twitter_card,
    site: FiSeo.initialized_config.default_twitter_site,
    image: FiSeo.initialized_config.default_twitter_image,
    description: FiSeo.initialized_config.default_twitter_description
  }
end
update_dynamic_seo_record() click to toggle source
# File lib/fi_seo.rb, line 155
def update_dynamic_seo_record
  if self.class.seoable_options[:check_for_changes]
    row = DynamicSeo.find_by_seoable_type_and_seoable_id(self.class.to_s, self.id)
    if row.nil?
      self.create_dynamic_seo_record
    else
      DynamicSeo.where(seoable_type: self.class.to_s).where(seoable_id: self.id)
                .update_all(title: self.title_value, description: self.description_value, keywords: self.keywords_value)
    end
  end
end