Commit d9dfb121 authored by Sylvester Keil's avatar Sylvester Keil

add support for sorting using numeric values

parent 542f772d
......@@ -200,17 +200,17 @@ Feature: Sorting BibTeX Bibliographies
And I have a file "_bibliography/references.bib":
"""
@book{ruby1,
title = {December},
title = {December 08},
year = {2008},
month = dec
}
@book{ruby2,
title = {March},
title = {March 08},
year = {2008},
month = mar
}
@book{ruby3,
title = {August},
title = {August 07},
year = {2007},
month = aug
}
......@@ -224,5 +224,5 @@ Feature: Sorting BibTeX Bibliographies
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"
Then "August 07" should come before "March 08" in "_site/scholar.html"
And "March 08" should come before "December 08" in "_site/scholar.html"
......@@ -28,7 +28,7 @@ Gem::Specification.new do |s|
s.add_runtime_dependency('jekyll', '~> 2.0')
s.add_runtime_dependency('citeproc-ruby', '~> 1.0')
s.add_runtime_dependency('csl-styles', '~> 1.0')
s.add_runtime_dependency('bibtex-ruby', '>= 4.0.6')
s.add_runtime_dependency('bibtex-ruby', '>= 4.0.8')
s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
......
......@@ -13,7 +13,7 @@ module Jekyll
'bibliography' => 'references.bib',
'repository' => nil,
'bibtex_options' => { :strip => false },
'bibtex_options' => { :strip => false, :parse_months => true },
'bibtex_filters' => [ :latex ],
'replace_strings' => true,
......
......@@ -141,16 +141,18 @@ module Jekyll
def sort(unsorted)
return unsorted if skip_sort?
puts unsorted.first.values_at(*sort_keys)
sorted = unsorted.sort_by { |e| e.values_at(*sort_keys) }
sorted = unsorted.sort_by { |e| e.values_at(*sort_keys).map(&:v) }
sorted.reverse! if config['order'] =~ /^(desc|reverse)/i
sorted
end
def sort_keys
@sort_kyes ||= Array(config['sort_by']).map { |key|
key.to_s.split(/\s*,\s*/)
}.flatten
return @sort_keys unless @sort_keys.nil?
@sort_keys = Array(config['sort_by'])
.map { |key| key.to_s.split(/\s*,\s*/) }
.flatten
.map { |key| key == 'month' ? 'month_numeric' : key }
end
def suppress_author?
......
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