From 1651c4bfc54864166af4a7083fbf322539baa450 Mon Sep 17 00:00:00 2001 From: Alex Ibrado Date: Fri, 1 Dec 2017 00:50:28 +0800 Subject: [PATCH] Check for nils, convert to DateTime before comparing --- lib/jekyll-paginate-v2/generator/utils.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/jekyll-paginate-v2/generator/utils.rb b/lib/jekyll-paginate-v2/generator/utils.rb index ecff844..2f90ab9 100644 --- a/lib/jekyll-paginate-v2/generator/utils.rb +++ b/lib/jekyll-paginate-v2/generator/utils.rb @@ -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 @@ -117,4 +127,4 @@ def self.sort_get_post_data(post_data, sort_field) end end # module PaginateV2 -end # module Jekyll \ No newline at end of file +end # module Jekyll