module RailsConnector
# Search Engine Optimization methods
module SEO
# The methods contained herein are attached to the Obj model class.
module ClassMethods
# Finds all objects that shall be included in the SEO sitemap.xml.
# On each exportable none-image object, included_in_seo_sitemap? is called.
# Overwrite included_in_seo_sitemap? in your +ObjExtensions+ to adjust the criteria.
def find_all_for_sitemap
start = Obj.homepage
children = start.toclist
grandchildren = children.map(&:toclist).flatten
([start] + children + grandchildren).select(&:included_in_seo_sitemap?)
end
end
# The methods contained herein are included in the Obj model.
module InstanceMethods
# Returns +true+ by default. Overwrite in your +ObjExtensions+ as you like.
def readable_for_googlebots?
true
end
# Default implementation: objects have to be active? and at least of one of: permitted for anyone (permitted_groups = []), readable_for_googlebots?.
# Overwrite in your +ObjExtensions+ as you like.
def included_in_seo_sitemap?
(permitted_groups.empty? || readable_for_googlebots?) && active?
end
# Returns an html-stripped Obj#body, truncated to 300 chars.
# Overwrite in your +ObjExtensions+ as you like. For example, point to a CMS field.
def seo_description
HTML::FullSanitizer.new.sanitize(body.strip.gsub(%r{[\n|\r]}, " ")).mb_chars[0,300] if body
end
# Returns +nil+ by default. Overwrite in your +ObjExtensions+ as you like.
# For example, point to a CMS field of your objects.
def seo_keywords
nil
end
end
def self.included(receiver) # :nodoc:
receiver.extend ClassMethods
receiver.send :include, InstanceMethods
end
end
end