Sha256: 386d24cc41d34c8852b69113196316684fcff8f2038de964bf45de8cdaf1bc59

Contents?: true

Size: 1.88 KB

Versions: 21

Compression:

Stored size: 1.88 KB

Contents

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 <tt>sitemap.xml</tt>.
      # On each exportable none-image object, <tt>included_in_seo_sitemap?</tt> is called.
      # Overwrite <tt>included_in_seo_sitemap?</tt> 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 <tt>active?</tt> and at least of one of: permitted for anyone (<tt>permitted_groups = []</tt>), <tt>readable_for_googlebots?</tt>.
      # Overwrite in your +ObjExtensions+ as you like.
      def included_in_seo_sitemap?
        (permitted_groups.empty? || readable_for_googlebots?) && active?
      end

      # Returns an html-stripped <tt>Obj#body</tt>, 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

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
infopark_rails_connector-6.8.0.210.ed204b0 lib/rails_connector/seo.rb
infopark_rails_connector-6.8.0.110.6570b45 lib/rails_connector/seo.rb
infopark_rails_connector-6.8.0.72.d18d096 lib/rails_connector/seo.rb
infopark_rails_connector-6.8.0.23.da7f96b lib/rails_connector/seo.rb
infopark_rails_connector-6.8.0.16.def5e85 lib/rails_connector/seo.rb
infopark_rails_connector-6.8.0.15.a24f5ff lib/rails_connector/seo.rb
infopark_rails_connector-6.8.0.beta.200.891.647580e lib/rails_connector/seo.rb
infopark_rails_connector-6.8.0.beta.200.889.d503e42 lib/rails_connector/seo.rb
infopark_rails_connector-6.8.0.beta.200.883.f5f063b lib/rails_connector/seo.rb
infopark_rails_connector-6.8.0.beta.200.884.4bd86e6 lib/rails_connector/seo.rb
infopark_rails_connector-6.8.0.beta.200.869.9609b39 lib/rails_connector/seo.rb
infopark_rails_connector-6.8.0.beta.200.856.8c0fec5 lib/rails_connector/seo.rb
infopark_rails_connector-6.8.0.beta.200.809.bdfa8c3 lib/rails_connector/seo.rb
infopark_rails_connector-6.8.0.beta.200.785.05d4af9 lib/rails_connector/seo.rb
infopark_rails_connector-6.8.0.beta.200.744.99f67fc lib/rails_connector/seo.rb
infopark_rails_connector-6.8.0.beta.200.720.44fbabd lib/rails_connector/seo.rb
infopark_rails_connector-6.8.0.beta.200.713.e5c3150 lib/rails_connector/seo.rb
infopark_rails_connector-6.8.0.beta.200.681.7c84f4a lib/rails_connector/seo.rb
infopark_rails_connector-6.8.0.beta.200.663.ceecdee lib/rails_connector/seo.rb
infopark_rails_connector-6.8.0.beta.200.650.7c93155 lib/rails_connector/seo.rb