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.

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:

Gemfile
group :jekyll_plugins do 
  gem 'jekyll_sort_natural'
end 

And then execute:

Shell
$ bundle

Usage Example

Case-insensitive category sort
{% 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.

* indicates a required field.

Please select the following to receive Mike Slinn’s newsletter:

You can unsubscribe at any time by clicking the link in the footer of emails.

Mike Slinn uses Mailchimp as his marketing platform. By clicking below to subscribe, you acknowledge that your information will be transferred to Mailchimp for processing. Learn more about Mailchimp’s privacy practices.