Skip to content

Instantly share code, notes, and snippets.

@darkoverlordofdata
Last active December 31, 2015 07:49
Show Gist options
  • Save darkoverlordofdata/7956924 to your computer and use it in GitHub Desktop.
Save darkoverlordofdata/7956924 to your computer and use it in GitHub Desktop.
Ya Sure, You Betcha - It's a Sortin' Huginn Pluginn
...
sort:
src: posts
by: date
direction: asc
dest: posts_asc
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
...
{% 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