mirror of
https://github.com/jekyll/jekyll.git
synced 2026-02-16 17:45:51 -05:00
Update item_property to recognize integers (#7878)
Merge pull request 7878
This commit is contained in:
@@ -368,15 +368,18 @@ module Jekyll
|
||||
end
|
||||
end
|
||||
|
||||
# rubocop:disable Performance/RegexpMatch
|
||||
FLOAT_LIKE = %r!\A\s*-?(?:\d+\.?\d*|\.\d+)\s*\Z!.freeze
|
||||
INTEGER_LIKE = %r!\A\s*-?\d+\s*\Z!.freeze
|
||||
private_constant :FLOAT_LIKE, :INTEGER_LIKE
|
||||
|
||||
# return numeric values as numbers for proper sorting
|
||||
def parse_sort_input(property)
|
||||
number_like = %r!\A\s*-?(?:\d+\.?\d*|\.\d+)\s*\Z!
|
||||
return property.to_f if property.to_s =~ number_like
|
||||
stringified = property.to_s
|
||||
return property.to_i if INTEGER_LIKE.match?(stringified)
|
||||
return property.to_f if FLOAT_LIKE.match?(stringified)
|
||||
|
||||
property
|
||||
end
|
||||
# rubocop:enable Performance/RegexpMatch
|
||||
|
||||
def as_liquid(item)
|
||||
case item
|
||||
|
||||
Reference in New Issue
Block a user