From c18405ffec743124c5780f6ad130e64d42ab9e74 Mon Sep 17 00:00:00 2001
From: ariseus <33930674+garywei944@users.noreply.github.com>
Date: Thu, 20 Jun 2024 11:40:34 -0400
Subject: [PATCH] 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/1fc04fde09f5ba11c4f9a6d72ed242f3d4e42475/_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](https://github.com/Shopify/liquid/issues/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 %}
{% if site.enable_publication_badges.altmetric and entry_has_altmetric_badge %}
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.
---
_layouts/bib.liquid | 31 ++++++++++++++++++++++---------
1 file changed, 22 insertions(+), 9 deletions(-)
diff --git a/_layouts/bib.liquid b/_layouts/bib.liquid
index a54aaa6..5b58600 100644
--- a/_layouts/bib.liquid
+++ b/_layouts/bib.liquid
@@ -249,9 +249,20 @@
{% endif %}
{% 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 %}
{% if site.enable_publication_badges.altmetric and entry_has_altmetric_badge %}
@@ -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 %}
@@ -277,12 +290,12 @@
{% if site.enable_publication_badges.dimensions and entry_has_dimensions_badge %}