diff --git a/features/sorting.feature b/features/sorting.feature index 8b851f1a5d4cb5eccb4021f24ec79a3bf65e5ba3..051f5b14fe610905bf5f2439331b12e8c9f197f8 100644 --- a/features/sorting.feature +++ b/features/sorting.feature @@ -190,3 +190,39 @@ Feature: Sorting BibTeX Bibliographies And the "_site/scholar.html" file should exist Then "Ruby Programming" should come before "Smalltalk" in "_site/scholar.html" And I should not see "Ruby Not Cited" 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" diff --git a/lib/jekyll/scholar/utilities.rb b/lib/jekyll/scholar/utilities.rb index cd5d567f02a7e356249211158874aec013f82eac..148327e813915ef1c6f1fb92ad161e2d524f44fe 100644 --- a/lib/jekyll/scholar/utilities.rb +++ b/lib/jekyll/scholar/utilities.rb @@ -141,11 +141,18 @@ module Jekyll def sort(unsorted) 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 end + def sort_keys + @sort_kyes ||= Array(config['sort_by']).map { |key| + key.to_s.split(/\s*,\s*/) + }.flatten + end + def suppress_author? !!@suppress_author end