Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
caesr-pub
jekyll-scholar
Commits
94a2630f
Commit
94a2630f
authored
Apr 19, 2014
by
Sylvester Keil
Browse files
sort cited-only bibliographies
fix #44
parent
cd44b10e
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
93 additions
and
6 deletions
+93
-6
features/sorting.feature
features/sorting.feature
+83
-0
features/step_definitions/scholar_steps.rb
features/step_definitions/scholar_steps.rb
+1
-0
lib/jekyll/scholar/tags/bibliography.rb
lib/jekyll/scholar/tags/bibliography.rb
+2
-0
lib/jekyll/scholar/utilities.rb
lib/jekyll/scholar/utilities.rb
+7
-6
No files found.
features/sorting.feature
View file @
94a2630f
...
@@ -67,3 +67,86 @@ Feature: Sorting BibTeX Bibliographies
...
@@ -67,3 +67,86 @@ Feature: Sorting BibTeX Bibliographies
And
the
"_site/scholar.html"
file should exist
And
the
"_site/scholar.html"
file should exist
Then
"2008"
should come before
"2007"
in
"_site/scholar.html"
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"
features/step_definitions/scholar_steps.rb
View file @
94a2630f
...
@@ -31,6 +31,7 @@ end
...
@@ -31,6 +31,7 @@ end
Then
(
/^"(.*)" should come before "(.*)" in "(.*)"$/
)
do
|
p1
,
p2
,
file
|
Then
(
/^"(.*)" should come before "(.*)" in "(.*)"$/
)
do
|
p1
,
p2
,
file
|
data
=
File
.
open
(
file
).
readlines
.
join
(
''
)
data
=
File
.
open
(
file
).
readlines
.
join
(
''
)
puts
data
m1
=
data
.
match
(
p1
)
m1
=
data
.
match
(
p1
)
m2
=
data
.
match
(
p2
)
m2
=
data
.
match
(
p2
)
...
...
lib/jekyll/scholar/tags/bibliography.rb
View file @
94a2630f
...
@@ -21,6 +21,8 @@ module Jekyll
...
@@ -21,6 +21,8 @@ module Jekyll
references
=
cited_references
.
uniq
.
map
do
|
key
|
references
=
cited_references
.
uniq
.
map
do
|
key
|
references
.
detect
{
|
e
|
e
.
key
==
key
}
references
.
detect
{
|
e
|
e
.
key
==
key
}
end
end
references
=
sort
references
end
end
bibliography
=
references
.
each_with_index
.
map
{
|
entry
,
index
|
bibliography
=
references
.
each_with_index
.
map
{
|
entry
,
index
|
...
...
lib/jekyll/scholar/utilities.rb
View file @
94a2630f
...
@@ -116,14 +116,15 @@ module Jekyll
...
@@ -116,14 +116,15 @@ module Jekyll
end
end
def
entries
def
entries
b
=
bibliography
[
query
||
config
[
'query'
]]
sort
bibliography
[
query
||
config
[
'query'
]]
end
unless
config
[
'sort_by'
]
==
'none'
def
sort
(
unsorted
)
b
=
b
.
sort_by
{
|
e
|
e
[
config
[
'sort_by'
]].
to_s
}
return
unsorted
if
config
[
'sort_by'
]
==
'none'
b
.
reverse!
if
config
[
'order'
]
=~
/^(desc|reverse)/i
end
b
sorted
=
unsorted
.
sort_by
{
|
e
|
e
[
config
[
'sort_by'
]].
to_s
}
sorted
.
reverse!
if
config
[
'order'
]
=~
/^(desc|reverse)/i
sorted
end
end
def
repository?
def
repository?
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment