diff options
| author | Andrew Lee <alee14498@gmail.com> | 2019-10-27 09:57:37 -0400 |
|---|---|---|
| committer | Andrew Lee <alee14498@gmail.com> | 2019-10-27 09:57:37 -0400 |
| commit | e62e7bb6b14555c9bbe5d40d217103984f4f80e6 (patch) | |
| tree | 21887d847dccacb47644eb6f74ce31326172303c /_includes/group-by-array | |
| parent | 716ea6ed2b64c921a799d872a07bfbd53b2a3e58 (diff) | |
| download | pokeworld-website-e62e7bb6b14555c9bbe5d40d217103984f4f80e6.tar.gz pokeworld-website-e62e7bb6b14555c9bbe5d40d217103984f4f80e6.tar.bz2 pokeworld-website-e62e7bb6b14555c9bbe5d40d217103984f4f80e6.zip | |
Rewrite progress
Diffstat (limited to '_includes/group-by-array')
| -rw-r--r-- | _includes/group-by-array | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/_includes/group-by-array b/_includes/group-by-array new file mode 100644 index 0000000..708de41 --- /dev/null +++ b/_includes/group-by-array @@ -0,0 +1,47 @@ +<!-- +# Jekyll Group-By-Array 0.1.0 +# https://github.com/mushishi78/jekyll-group-by-array +# © 2015 Max White <mushishi78@gmail.com> +# MIT License +--> + +<!-- Initialize --> +{% assign __empty_array = '' | split: ',' %} +{% assign group_names = __empty_array %} +{% assign group_items = __empty_array %} + +<!-- Map --> +{% assign __names = include.collection | map: include.field %} + +<!-- Flatten --> +{% assign __names = __names | join: ',' | join: ',' | split: ',' %} + +<!-- Uniq --> +{% assign __names = __names | sort %} +{% for name in __names %} + +<!-- If not equal to previous then it must be unique as sorted --> +{% unless name == previous %} + +<!-- Push to group_names --> +{% assign group_names = group_names | push: name %} +{% endunless %} + +{% assign previous = name %} +{% endfor %} + + +<!-- group_items --> +{% for name in group_names %} + +<!-- Collect if contains --> +{% assign __item = __empty_array %} +{% for __element in include.collection %} +{% if __element[include.field] contains name %} +{% assign __item = __item | push: __element %} +{% endif %} +{% endfor %} + +<!-- Push to group_items --> +{% assign group_items = group_items | push: __item %} +{% endfor %}
\ No newline at end of file |
