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