Mike Slinn
Mike Slinn

jekyll_sort_natural

Published 2020-10-03. Last modified 2023-05-18.
Time to read: 1 minutes.

This page is part of the jekyll_plugins collection, categorized under Jekyll.

jekyll_sort_natural is a Jekyll plugin that sorts hashes using String#casecmp,the case-insensitive version of String#<=>.

See Add sort_natural to jekyll/filters.rb. This plugin overrides sort_natural, provided by Liquid v4.

Installation

Add the following highlighted line to your Jekyll project's Gemfile, within the jekyll_plugins group:

Shell
group :jekyll_plugins do 
  gem 'jekyll_sort_natural'
end 

And then execute:

Shell
$ bundle

Usage Example

Shell
{% assign sorted_categories = site.categories | sort_natural %}

For More Information

By default, Enumerable#sort uses <=> for comparisons.

See Add sort_natural to jekyll/filters.rb. This plugin overrides sort_natural provided by Liquid 4.

Acknowledgement

This plugin contains code modified from tkrotoff.