class Jekyll::PaginateV2::Generator::PaginationIndexer

def self.index_posts_by(all_posts, index_key)


Create a hash index for all post based on a key in the post.data table
def self.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.downcase.strip
      # If the key is a delimetered list of values 

      # (meaning the user didn't use an array but a string with commas)

      key.split(/;|,/).each do |k_split|
        k_split = k_split.to_s.downcase.strip #Clean whitespace and junk

        if !index.has_key?(k_split)
          index[k_split.to_s] = []
        end
        index[k_split.to_s] << post
      end
    end
  end
  return index
end # function index_posts_by