DocumentDrop: add `#<=>` which sorts by date (falling back to path)

This commit is contained in:
Parker Moore 2016-03-31 13:39:08 -07:00
parent f2aa15555b
commit 4b471fe9fb
No known key found for this signature in database
GPG Key ID: 193CDEBA72063C58
1 changed files with 7 additions and 0 deletions

View File

@ -20,6 +20,13 @@ module Jekyll
fallback_data['excerpt'].to_s
end
def <=>(other)
return nil unless other.is_a? DocumentDrop
cmp = self['date'] <=> other['date']
cmp = self['path'] <=> other['path'] if cmp.nil? || cmp == 0
cmp
end
private
def_delegator :@obj, :data, :fallback_data
end