Skip to content

Commit

Permalink
Check for nils, convert to DateTime before comparing
Browse files Browse the repository at this point in the history
  • Loading branch information
ibrado authored and sverrirs committed Dec 2, 2017
1 parent 89caed0 commit 1651c4b
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/jekyll-paginate-v2/generator/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ def self.sort_values(a, b)
return a.downcase <=> b.downcase
end

if a.nil? && !b.nil?
return -1
elsif !a.nil? && b.nil?
return 1
end

if a.respond_to?('to_datetime') && b.respond_to?('to_datetime')
return a.to_datetime <=> b.to_datetime
end

# By default use the built in sorting for the data type
return a <=> b
end
Expand Down Expand Up @@ -117,4 +127,4 @@ def self.sort_get_post_data(post_data, sort_field)
end

end # module PaginateV2
end # module Jekyll
end # module Jekyll

0 comments on commit 1651c4b

Please sign in to comment.