Skip to content

Commit c429a80

Browse files
rohandebsarkaralshedivat
authored andcommitted
Adds support max_author_limit (alshedivat#732)
* Adds support max author limit * typo * fix * display all authors by default * Added an example * Added 'and' before the last author * Improve hiding/showing more authors * Add title text Co-authored-by: Maruan Al-Shedivat <[email protected]> Co-authored-by: Maruan <[email protected]>
1 parent 1e7e4c8 commit c429a80

File tree

5 files changed

+86
-6
lines changed

5 files changed

+86
-6
lines changed

_bibliography/papers.bib

+8
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,11 @@ @article{einstein1905electrodynamics
7171
author={Einstein, A.},
7272
year={1905}
7373
}
74+
75+
@book{przibram1967letters,
76+
bibtex_show={true},
77+
title={Letters on wave mechanics},
78+
author={Einstein, Albert and Schrödinger, Erwin and Planck, Max and Lorentz, Hendrik Antoon and Przibram, Karl},
79+
year={1967},
80+
publisher={Vision}
81+
}

_config.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,11 @@ scholar:
229229

230230
query: "@*"
231231

232-
filtered_bibtex_keywords: [abbr, abstract, arxiv, bibtex_show, html, pdf, selected, supp, blog, code, poster, slides, website, preview] # Filter out certain bibtex entry keywords used internally from the bib output
232+
# Filter out certain bibtex entry keywords used internally from the bib output
233+
filtered_bibtex_keywords: [abbr, abstract, arxiv, bibtex_show, html, pdf, selected, supp, blog, code, poster, slides, website, preview]
234+
235+
# Maximum number of authors to be shown, other authors will be visible on hover, leave blank to show all authors
236+
max_author_limit: 3
233237

234238
# -----------------------------------------------------------------------------
235239
# Responsive WebP Images

_data/coauthors.yml

+16
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,19 @@
1616

1717
- firstname: ["Carl Philipp Emanuel", "C. P. E."]
1818
url: https://en.wikipedia.org/wiki/Carl_Philipp_Emanuel_Bach
19+
20+
"Przibram":
21+
- firstname: ["Karl"]
22+
url: https://link.springer.com/article/10.1007/s00016-019-00242-z
23+
24+
"Schrödinger":
25+
- firstname: ["Erwin"]
26+
url: https://en.wikipedia.org/wiki/Erwin_Schr%C3%B6dinger
27+
28+
"Lorentz":
29+
- firstname: ["Hendrik Antoon"]
30+
url: https://en.wikipedia.org/wiki/Hendrik_Lorentz
31+
32+
"Planck":
33+
- firstname: ["Max"]
34+
url: https://en.wikipedia.org/wiki/Max_Planck

_layouts/bib.html

+48-5
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,17 @@
2727
<div class="title">{{entry.title}}</div>
2828
<!-- Author -->
2929
<div class="author">
30-
{%- for author in entry.author_array -%}
30+
{% assign author_array_size = entry.author_array | size %}
31+
32+
{%- if site.max_author_limit and author_array_size > site.max_author_limit %}
33+
{% assign author_array_limit = site.max_author_limit %}
34+
{% else %}
35+
{% assign author_array_limit = author_array_size %}
36+
{% endif %}
37+
38+
{%- for author in entry.author_array limit: author_array_limit -%}
3139
{%- assign author_is_self = false -%}
32-
{%- if author.last == site.scholar.last_name%}
40+
{%- if author.last == site.scholar.last_name %}
3341
{%- if site.scholar.first_name contains author.first -%}
3442
{%- assign author_is_self = true -%}
3543
{%- endif -%}
@@ -62,18 +70,53 @@
6270
{%- endif -%}
6371
{%- endif -%}
6472
{%- else -%}
73+
{%- if author_array_limit == author_array_size %} and {% endif %}
6574
{% if author_is_self -%}
66-
and <em>{{author.last}}, {{author.first}}</em>
75+
<em>{{author.last}}, {{author.first}}</em>
6776
{% else -%}
6877
{%- if coauthor_url -%}
69-
and <a href="{{coauthor_url}}">{{author.last}}, {{author.first}}</a>
78+
<a href="{{coauthor_url}}">{{author.last}}, {{author.first}}</a>
7079
{% else -%}
71-
and {{author.last}}, {{author.first}}
80+
{{author.last}}, {{author.first}}
7281
{%- endif -%}
7382
{%- endif -%}
7483
{%- endunless -%}
7584
{%- endif -%}
7685
{%- endfor %}
86+
87+
{% assign more_authors = author_array_size | minus: author_array_limit %}
88+
89+
{%- if more_authors > 0 %}
90+
{% assign more_authors_hide = more_authors | append: " more author" %}
91+
{% if more_authors > 1 %}
92+
{% assign more_authors_hide = more_authors_hide | append: "s" %}
93+
{% endif %}
94+
{% assign more_authors_show = '' %}
95+
{%- for author in entry.author_array offset: author_array_limit -%}
96+
{% assign more_authors_show = more_authors_show | append: author.last | append: ", " | append: author.first %}
97+
{% unless forloop.last %}
98+
{% assign more_authors_show = more_authors_show | append: ",&nbsp;" %}
99+
{% endunless %}
100+
{%- endfor -%}
101+
and
102+
<span
103+
class="more-authors"
104+
title="click to view {{more_authors_hide}}"
105+
onclick="
106+
var element = $('span.more-authors');
107+
var more_authors_text = element.text() == '{{more_authors_hide}}' ? '{{more_authors_show}}' : '{{more_authors_hide}}';
108+
var cursorPosition = 0;
109+
var textAdder = setInterval(function(){
110+
element.text(more_authors_text.substring(0, cursorPosition + 1));
111+
element.attr('title', '');
112+
if (++cursorPosition == more_authors_text.length){
113+
clearInterval(textAdder);
114+
}
115+
}, 15);
116+
"
117+
>{{more_authors_hide}}</span>
118+
{% endif %}
119+
77120
</div>
78121

79122
<!-- Journal/Book title and date -->

_sass/_base.scss

+9
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,15 @@ footer.sticky-bottom {
520520
border-bottom: 1px solid;
521521
font-style: normal;
522522
}
523+
> span.more-authors {
524+
color: var(--global-text-color-light);
525+
border-bottom: 1px dashed var(--global-text-color-light);
526+
cursor: pointer;
527+
&:hover {
528+
color: var(--global-text-color);
529+
border-bottom: 1px dashed var(--global-text-color);
530+
}
531+
}
523532
}
524533
.links {
525534
a.btn {

0 commit comments

Comments
 (0)