class Jekyll::J1Paginator::AutoPages::Utils

Public Class Methods

ap_index_posts_by(all_posts, index_key) click to toggle source
# File lib/j1-paginator/autopages/utils.rb, line 42
def self.ap_index_posts_by(all_posts, index_key)
  return nil if all_posts.nil?
  return all_posts if index_key.nil?
  index = {}
  all_posts.each do |post|
    next if post.data.nil?
    next if !post.data.has_key?(index_key)
    next if post.data[index_key].nil?
    next if post.data[index_key].size <= 0
    next if post.data[index_key].to_s.strip.length == 0

    # Only tags and categories come as premade arrays, locale does not, so convert any data
    # elements that are strings into arrays
    post_data = post.data[index_key]
    if post_data.is_a?(String)
      post_data = post_data.split(/;|,|\s/)
    end

    post_data.each do |key|
      key = key.to_s.strip
      processed_key = key.downcase #Clean whitespace and junk
      if !index.has_key?(processed_key)
        # Need to store the original key value here so that I can present it to the users as a page variable they can use (unmodified, e.g. tags not being 'sci-fi' but "Sci-Fi")
        # Also, only interested in storing all the keys not the pages in this case
        index[processed_key] = [processed_key, key]
      end
    end
  end
  return index
end
collect_all_docs(site_collections) click to toggle source

Static: returns all documents from all collections defined in the hash of collections passed in excludes all pagination pages though

# File lib/j1-paginator/autopages/utils.rb, line 32
def self.collect_all_docs(site_collections)
  coll = []
  site_collections.each do |coll_name, coll_data|
    if !coll_data.nil?
      coll += coll_data.docs.select { |doc| !doc.data.has_key?('pagination') }.each{ |doc| doc.data['__coll'] = coll_name } # Exclude all pagination pages and then for every page store it's collection name
    end
  end
  return coll
end
format_cat_macro(toFormat, category, slugify_config=nil) click to toggle source

Static: returns a fully formatted string with the category macro (:cat) replaced

# File lib/j1-paginator/autopages/utils.rb, line 16
def self.format_cat_macro(toFormat, category, slugify_config=nil)
  slugify_mode = slugify_config.has_key?('mode') ? slugify_config['mode'] : nil
  slugify_cased = slugify_config.has_key?('cased') ? slugify_config['cased'] : false
  return toFormat.sub(':cat', Jekyll::Utils.slugify(category.to_s, mode:slugify_mode, cased:slugify_cased))
end
format_coll_macro(toFormat, collection, slugify_config=nil) click to toggle source

Static: returns a fully formatted string with the collection macro (:coll) replaced

# File lib/j1-paginator/autopages/utils.rb, line 24
def self.format_coll_macro(toFormat, collection, slugify_config=nil)
  slugify_mode = slugify_config.has_key?('mode') ? slugify_config['mode'] : nil
  slugify_cased = slugify_config.has_key?('cased') ? slugify_config['cased'] : false
  return toFormat.sub(':coll', Jekyll::Utils.slugify(collection.to_s, mode:slugify_mode, cased:slugify_cased))
end
format_tag_macro(toFormat, tag, slugify_config=nil) click to toggle source

Static: returns a fully formatted string with the tag macro (:tag) replaced

# File lib/j1-paginator/autopages/utils.rb, line 8
def self.format_tag_macro(toFormat, tag, slugify_config=nil)
  slugify_mode = slugify_config.has_key?('mode') ? slugify_config['mode'] : nil
  slugify_cased = slugify_config.has_key?('cased') ? slugify_config['cased'] : false
  return toFormat.sub(':tag', Jekyll::Utils.slugify(tag.to_s, mode:slugify_mode, cased:slugify_cased))
end