Skip to content

Commit

Permalink
Reduce ABC size of method
Browse files Browse the repository at this point in the history
  • Loading branch information
ashmaroli committed Mar 3, 2017
1 parent 9efe212 commit d70d798
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions lib/jekyll/collection.rb
Expand Up @@ -249,18 +249,23 @@ def rearrange_docs!
end
end

assign_sort_index(docs)
docs.sort_by! { |d| d.data["sort_index"] }
rescue
# Collect all documents without the virtual `sort_index` key defined and assign
# the key with a value equal to the total no. of documents in the main collection.
#
# Such documents will be sorted alphabetically and appear at the end of the custom
# array.
docs.select { |d| d.data["sort_index"].nil? }.each do |doc|
doc.data["sort_index"] = docs.size
end
end

docs.sort_by! { |d| d.data["sort_index"] }
# Assign a virtual `sort_index` to all Jekyll::Document objects in the current
# collection.
#
# Collect all documents without the virtual `sort_index` key defined and assign
# the key with a value equal to the total no. of documents in the main collection.
# Such documents will be sorted alphabetically and appear at the end of the custom
# array.
#
# documents - the array of Jekyll::Document objects from the current Collection
def assign_sort_index(documents)
documents.select { |d| d.data["sort_index"].nil? }.each do |document|
document.data["sort_index"] = documents.size
end
end

def read_static_file(file_path, full_path)
Expand Down

0 comments on commit d70d798

Please sign in to comment.