Skip to content

Commit fefa247

Browse files
authored
Fix Altmetric badge not correctly set when Altmetric id is provided (#2522)
To reproduce the bug: ```bibtex @inproceedings{Vaswani2017AttentionIA, title = {Attention is All you Need}, author = {Ashish Vaswani and Noam M. Shazeer and Niki Parmar and Jakob Uszkoreit and Llion Jones and Aidan N. Gomez and Lukasz Kaiser and Illia Polosukhin}, booktitle = {Neural Information Processing Systems}, year = {2017}, doi = {10.48550/arXiv.1706.03762}, altmetric = {21021191} } ``` The bug is 1. It seems to be some weird property of the liquid template that [line 252-254](https://github.com/alshedivat/al-folio/blob/8d82670ff170f98e7d7ea5434428234a8216d460/_layouts/bib.liquid#L252-L254) doesn't work at all. According to [this post](https://stackoverflow.com/questions/59887447/liquid-how-to-assign-the-output-of-an-operator-to-a-variable) and [this issue](Shopify/liquid#236), liquid doesn't support assign the output of operator to a variable nor a ternary operator. So based on my console log, the value of `entry_has_altmetric_badge` is always a string value of `entry.altmetric` when altmetric is provided in bibtex. ```liquid {% assign entry_has_altmetric_badge = entry.altmetric or entry.doi or entry.eprint or entry.pmid or entry.isbn %} {% assign entry_has_dimensions_badge = entry.dimensions or entry.doi or entry.pmid %} {% assign entry_has_google_scholar_badge = entry.google_scholar_id %} {% if entry_has_altmetric_badge or entry_has_dimensions_badge or entry_has_google_scholar_badge %} <div class="badges"> {% if site.enable_publication_badges.altmetric and entry_has_altmetric_badge %} <span ... ``` Note that this could be problematic that a string in liquid is always evaluated as true as long as it is defined regardless if it is "" or "false". [reference](https://shopify.github.io/liquid/basics/truthy-and-falsy/) 2. when altmetric is defined in bibtex, now the order of set attribute to badge is eprint > doi > altmetric id > pmid > ISBN, and the badge doesn't work when an arxiv doi is provided. I think the expected behavior should be 1. as documented in CUSTOMIZE.md, only render the badge when the entry is set to either "true" or the altmetric id. (It could also implement to always render the badge whenever doi or other related attribute is set, and set altmetric to "false" to disable it) ```md - `altmetric`: Adds an [Altmetric](https://www.altmetric.com/) badge (Note: if DOI is provided just use `true`, otherwise only add the altmetric identifier here - the link is generated automatically) ``` 2. if the almetric id is set, use it first.
1 parent cd020af commit fefa247

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

_layouts/bib.liquid

+22-9
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,20 @@
249249
{% endif %}
250250
</div>
251251
{% if site.enable_publication_badges %}
252-
{% assign entry_has_altmetric_badge = entry.altmetric or entry.doi or entry.eprint or entry.pmid or entry.isbn %}
253-
{% assign entry_has_dimensions_badge = entry.dimensions or entry.doi or entry.pmid %}
254-
{% assign entry_has_google_scholar_badge = entry.google_scholar_id %}
252+
{% assign entry_has_altmetric_badge = false %}
253+
{% if entry.altmetric and entry.altmetric != 'false' %}
254+
{% assign entry_has_altmetric_badge = true %}
255+
{% endif %}
256+
257+
{% assign entry_has_dimensions_badge = false %}
258+
{% if entry.dimensions and entry.dimensions != 'false' %}
259+
{% assign entry_has_dimensions_badge = true %}
260+
{% endif %}
261+
262+
{% assign entry_has_google_scholar_badge = false %}
263+
{% if entry.google_scholar_id %}
264+
{% assign entry_has_google_scholar_badge = true %}
265+
{% endif %}
255266
{% if entry_has_altmetric_badge or entry_has_dimensions_badge or entry_has_google_scholar_badge %}
256267
<div class="badges">
257268
{% if site.enable_publication_badges.altmetric and entry_has_altmetric_badge %}
@@ -261,12 +272,14 @@
261272
data-hide-less-than="15"
262273
data-badge-type="2"
263274
data-badge-popover="right"
264-
{% if entry.eprint %}
275+
{% if entry.altmetric != blank and entry.altmetric != 'true' %}
276+
data-altmetric-id="{{ entry.altmetric }}"
277+
{% elsif entry.arxiv %}
278+
data-arxiv-id="{{ entry.arxiv }}"
279+
{% elsif entry.eprint %}
265280
data-arxiv-id="{{ entry.eprint }}"
266281
{% elsif entry.doi %}
267282
data-doi="{{ entry.doi }}"
268-
{% elsif entry.altmetric %}
269-
data-altmetric-id="{{ entry.altmetric }}"
270283
{% elsif entry.pmid %}
271284
data-pmid="{{ entry.pmid }}"
272285
{% elsif entry.isbn %}
@@ -277,12 +290,12 @@
277290
{% if site.enable_publication_badges.dimensions and entry_has_dimensions_badge %}
278291
<span
279292
class="__dimensions_badge_embed__"
280-
{% if entry.doi %}
293+
{% if entry.dimensions != blank and entry.dimensions != 'true' %}
294+
data-id="{{ entry.dimensions }}"
295+
{% elsif entry.doi %}
281296
data-doi="{{ entry.doi }}"
282297
{% else %}
283298
data-pmid="{{ entry.pmid }}"
284-
{% else %}
285-
data-id="{{ entry.dimensions }}"
286299
{% endif %}
287300
data-hide-zero-citations="true"
288301
data-style="small_rectangle"

0 commit comments

Comments
 (0)