Commit 959de535 authored by Sylvester Keil's avatar Sylvester Keil

add support for multiple sort keys

see #69
parent c2acfaa7
...@@ -190,3 +190,39 @@ Feature: Sorting BibTeX Bibliographies ...@@ -190,3 +190,39 @@ Feature: Sorting BibTeX Bibliographies
And the "_site/scholar.html" file should exist And the "_site/scholar.html" file should exist
Then "Ruby Programming" should come before "Smalltalk" in "_site/scholar.html" Then "Ruby Programming" should come before "Smalltalk" in "_site/scholar.html"
And I should not see "<i>Ruby Not Cited</i>" in "_site/scholar.html" And I should not see "<i>Ruby Not Cited</i>" in "_site/scholar.html"
@tags @sorting @wip
Scenario: Sort By Year And Month
Given I have a scholar configuration with:
| key | value |
| sort_by | year, month |
And I have a "_bibliography" directory
And I have a file "_bibliography/references.bib":
"""
@book{ruby1,
title = {December},
year = {2008},
month = dec
}
@book{ruby2,
title = {March},
year = {2008},
month = mar
}
@book{ruby3,
title = {August},
year = {2007},
month = aug
}
"""
And I have a page "scholar.html":
"""
---
---
{% bibliography %}
"""
When I run jekyll
Then the _site directory should exist
And the "_site/scholar.html" file should exist
Then "August" should come before "March" in "_site/scholar.html"
# And "March" should come before "December" in "_site/scholar.html"
...@@ -141,11 +141,18 @@ module Jekyll ...@@ -141,11 +141,18 @@ module Jekyll
def sort(unsorted) def sort(unsorted)
return unsorted if skip_sort? return unsorted if skip_sort?
sorted = unsorted.sort_by { |e| e[config['sort_by']].to_s } puts unsorted.first.values_at(*sort_keys)
sorted = unsorted.sort_by { |e| e.values_at(*sort_keys) }
sorted.reverse! if config['order'] =~ /^(desc|reverse)/i sorted.reverse! if config['order'] =~ /^(desc|reverse)/i
sorted sorted
end end
def sort_keys
@sort_kyes ||= Array(config['sort_by']).map { |key|
key.to_s.split(/\s*,\s*/)
}.flatten
end
def suppress_author? def suppress_author?
!!@suppress_author !!@suppress_author
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment