Commit 94a2630f authored by Sylvester Keil's avatar Sylvester Keil

sort cited-only bibliographies

fix #44
parent cd44b10e
......@@ -67,3 +67,86 @@ Feature: Sorting BibTeX Bibliographies
And the "_site/scholar.html" file should exist
Then "2008" should come before "2007" in "_site/scholar.html"
@tags @sorting @cited_only
Scenario: Sort By Year Cited Only
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 = {Ruby Not Cited},
author = {Flanagan, David and Matsumoto, Yukihiro},
year = {2007},
publisher = {O'Reilly Media}
}
@book{smalltalk,
title = {Smalltalk Best Practice Patterns},
author = {Kent Beck},
year = {1996},
publisher = {Prentice Hall}
}
"""
And I have a page "scholar.html":
"""
---
---
{% cite ruby1 %}
{% cite smalltalk %}
{% bibliography --cited %}
"""
When I run jekyll
Then the _site directory should exist
And the "_site/scholar.html" file should exist
Then "Smalltalk" should come before "Ruby Programming" in "_site/scholar.html"
And I should not see "<i>Ruby Not Cited</i>" in "_site/scholar.html"
@tags @sorting @cited_only
Scenario: Reverse Sort Order Cited Only
Given I have a scholar configuration with:
| key | value |
| sort_by | year |
| order | descending |
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 = {Ruby Not Cited},
author = {Flanagan, David and Matsumoto, Yukihiro},
year = {2007},
publisher = {O'Reilly Media}
}
@book{smalltalk,
title = {Smalltalk Best Practice Patterns},
author = {Kent Beck},
year = {1996},
publisher = {Prentice Hall}
}
"""
And I have a page "scholar.html":
"""
---
---
{% cite ruby1 %}
{% cite smalltalk %}
{% bibliography --cited %}
"""
When I run jekyll
Then the _site directory should exist
And the "_site/scholar.html" file should exist
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"
......@@ -31,6 +31,7 @@ end
Then(/^"(.*)" should come before "(.*)" in "(.*)"$/) do |p1, p2, file|
data = File.open(file).readlines.join('')
puts data
m1 = data.match(p1)
m2 = data.match(p2)
......
......@@ -21,6 +21,8 @@ module Jekyll
references = cited_references.uniq.map do |key|
references.detect { |e| e.key == key }
end
references = sort references
end
bibliography = references.each_with_index.map { |entry, index|
......
......@@ -116,14 +116,15 @@ module Jekyll
end
def entries
b = bibliography[query || config['query']]
sort bibliography[query || config['query']]
end
unless config['sort_by'] == 'none'
b = b.sort_by { |e| e[config['sort_by']].to_s }
b.reverse! if config['order'] =~ /^(desc|reverse)/i
end
def sort(unsorted)
return unsorted if config['sort_by'] == 'none'
b
sorted = unsorted.sort_by { |e| e[config['sort_by']].to_s }
sorted.reverse! if config['order'] =~ /^(desc|reverse)/i
sorted
end
def repository?
......
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