Skip to content

Commit

Permalink
Fix Altmetric badge not correctly set when Altmetric id is provided (…
Browse files Browse the repository at this point in the history
…#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.
  • Loading branch information
garywei944 authored and ngmarchant committed Jun 21, 2024
1 parent 3911f03 commit a6a5a97
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions _layouts/bib.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,20 @@
{% endif %}
</div>
{% if site.enable_publication_badges %}
{% 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 %}
{% assign entry_has_altmetric_badge = false %}
{% if entry.altmetric and entry.altmetric != 'false' %}
{% assign entry_has_altmetric_badge = true %}
{% endif %}

{% assign entry_has_dimensions_badge = false %}
{% if entry.dimensions and entry.dimensions != 'false' %}
{% assign entry_has_dimensions_badge = true %}
{% endif %}

{% assign entry_has_google_scholar_badge = false %}
{% if entry.google_scholar_id %}
{% assign entry_has_google_scholar_badge = true %}
{% endif %}
{% 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 %}
Expand All @@ -261,12 +272,14 @@
data-hide-less-than="15"
data-badge-type="2"
data-badge-popover="right"
{% if entry.eprint %}
{% if entry.altmetric != blank and entry.altmetric != 'true' %}
data-altmetric-id="{{ entry.altmetric }}"
{% elsif entry.arxiv %}
data-arxiv-id="{{ entry.arxiv }}"
{% elsif entry.eprint %}
data-arxiv-id="{{ entry.eprint }}"
{% elsif entry.doi %}
data-doi="{{ entry.doi }}"
{% elsif entry.altmetric %}
data-altmetric-id="{{ entry.altmetric }}"
{% elsif entry.pmid %}
data-pmid="{{ entry.pmid }}"
{% elsif entry.isbn %}
Expand All @@ -277,12 +290,12 @@
{% if site.enable_publication_badges.dimensions and entry_has_dimensions_badge %}
<span
class="__dimensions_badge_embed__"
{% if entry.doi %}
{% if entry.dimensions != blank and entry.dimensions != 'true' %}
data-id="{{ entry.dimensions }}"
{% elsif entry.doi %}
data-doi="{{ entry.doi }}"
{% else %}
data-pmid="{{ entry.pmid }}"
{% else %}
data-id="{{ entry.dimensions }}"
{% endif %}
data-hide-zero-citations="true"
data-style="small_rectangle"
Expand Down

0 comments on commit a6a5a97

Please sign in to comment.