Commit 9ecfd78c authored by Sylvester Keil's avatar Sylvester Keil

convert nil to bibtex value when sorting

fix #77
parent be176478
......@@ -34,6 +34,42 @@ Feature: Sorting BibTeX Bibliographies
And the "_site/scholar.html" file should exist
Then "2007" should come before "2008" in "_site/scholar.html"
@tags @sorting
Scenario: Sort By Year With Nil Values
Given I have a scholar configuration with:
| key | value |
| sort_by | year |
And I have a "_bibliography" directory
And I have a file "_bibliography/references.bib":
"""
@book{ruby1,
title = {The Ruby Programming Language},
author = {Flanagan, David and Matsumoto, Yukihiro},
year = {2008},
publisher = {O'Reilly Media}
}
@book{ruby2,
title = {Nil}
}
@book{ruby3,
title = {The Ruby Programming Language},
author = {Flanagan, David and Matsumoto, Yukihiro},
year = {2007},
publisher = {O'Reilly Media}
}
"""
And I have a page "scholar.html":
"""
---
---
{% bibliography -f references %}
"""
When I run jekyll
Then the _site directory should exist
And the "_site/scholar.html" file should exist
Then "Nil" should come before "Ruby" in "_site/scholar.html"
And "2007" should come before "2008" in "_site/scholar.html"
@tags @sorting
Scenario: Reverse Sort Order
Given I have a scholar configuration with:
......
......@@ -141,7 +141,10 @@ module Jekyll
def sort(unsorted)
return unsorted if skip_sort?
sorted = unsorted.sort_by { |e| e.values_at(*sort_keys) }
sorted = unsorted.sort_by do |e|
e.values_at(*sort_keys).map { |v| v.nil? ? BibTeX::Value.new : v }
end
sorted.reverse! if config['order'] =~ /^(desc|reverse)/i
sorted
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