Sorting: How to use Liquid's filter instead of Jekyll's?



I want to sort the content of a custom data file (YAML), located in _data directory, before
using it in a GitHub page. Since Jekyll’s sort filter raises an error/exception instead of just
warn and gracefully ignore/pass-through items which cannot be sorted (like nil, different
data types or hash against hash), it is useless, because I want to handle (drop, modify,
replace, etc.) those datas in page source itself – think of a try/catch block.

As far as I understand, the Liquid sort filter seems not to raise an exception and therefore
I would give it a try but don’t know how to syntactically specify this filter.


The custom data file may be edited by users not very familar with Jekyll/Liquid/YAML etc.
So, when there is a “mistake” (items the sort filter cannot handle), the exception raised:

  • points to the HTML and not to the YAML source file
  • offers a very imprecise number of error line (just a guess, due to not take
    file front matter and/or comment lines into account)

This may be too confusing to contributors and they probably give up because life is too short.

Thanks for any input but hacks like wrapping potential failing data into strings by using
group_by_exp filter or things that increase complexity or pollute source is not an option.

I want a sort filter that doesn’t touch and pass-through data it cannot handle without
raising unnecessary exceptions. Something like {{ data | join: ', ' }} which just
simply works for boolean, number, string types and arrays (of mixed data types).



I must admit that I haven’t understood your problem, but got curious and found this…:

Jekyll uses the Liquid templating language to process templates. All of the standard Liquid tags and filters are supported.



My point is that both, Jekyll and Liquid, have their own ideas how to implement sorting.
Thus, two different implementation exists, the Jekyll sort filter and the Liquid sort filter.

Now my origin point: How to select the latter sort filter when the former has the same
name (probably in the same namespace)?

To hopefully be more specific on my second point, I cannot believe a filter stops the whole
page build (like Jekyll’s sort implementation) when it cannot handle a (proper) data type.

<rhetorical>How many websites would lose their audience if a browser stops the page
rendering when it founds an unknown/unsupported CSS property?</rhetorical>


Thanks for your explanation, @floyd!
I hope some else will show up with and answer to your question. Meanwhile, I’ll keep reading through this issue: (:


I fear that doesn’t gonna happen because I realised I’ve expected too much from
a simple template language like Liquid. We can be thankful for control flow
structures and variables.

Differentiate between data types is beyond the feature of a language that
mostly just delegate its functionality to an underlying system (which does the
real work).

My fault was to use YAML which provides some kind of data types (null, boolean,
string, sequence, map, etc.). I better have to use CSV as custom data file
because all is just a string (which probably can be interpreted as a date, number
or whatelse).

Thank you @lsrdg for your response and links.



Wow. I actually learned a lot here. Thanks, @floyd .

Are you sure it is not worth an issue on github? Most likely you were not the first to face this kind of problem. If it was not on GH-pages, you could probably run a script to process that data before building. However, I must admit that I was expecting that something like capture and/or assign would be able with that…

Thanks for your question and explanations. Again, learned a lot. :+1:


Sorry floyd, but it is not possible to use Liquid’s sort filters instead of Jekyll’s out of the box.

What you could do is create a plugin to override Jekyll’s sort filters with Liquid’s.