Last active
December 31, 2015 07:49
-
-
Save darkoverlordofdata/7956924 to your computer and use it in GitHub Desktop.
Ya Sure, You Betcha - It's a Sortin' Huginn Pluginn
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
sort: | |
src: posts | |
by: date | |
direction: asc | |
dest: posts_asc |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = (site) -> | |
by = site.sort.by ? 'date' | |
# | |
# Get the list of items to sort | |
# | |
site[site.sort.dest] = (item for item in site[site.sort.src]) | |
# | |
# sort in descending or ascending order | |
# | |
site[site.sort.dest].sort switch site.sort.direction ? 'asc' | |
when 'desc' | |
(a, b) -> | |
if a[by] < b[by] then 1 else if a[by] > b[by] then -1 else 0 | |
else | |
(a, b) -> | |
if a[by] > b[by] then 1 else if a[by] < b[by] then -1 else 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
{% for post in site.posts_asc limit: 5 %} | |
<li><a href="/katra{{ post.url }}">{{ post.title }}</a></li> | |
{% endfor %} | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment