Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 42 additions & 7 deletions _layouts/bib.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -253,31 +253,52 @@
</div>
{% if site.enable_publication_badges %}
{% assign entry_has_altmetric_badge = false %}
{% if entry.altmetric and entry.altmetric != 'false' %}
{% assign entry_has_altmetric_badge = true %}
{% if entry.altmetric != 'false' %}
{% if entry.altmetric or entry.arxiv or entry.eprint or entry.doi or entry.pmid or entry.isbn %}
{% assign entry_has_altmetric_badge = true %}
{% endif %}
{% endif %}

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

{% assign entry_has_google_scholar_badge = false %}
{% if entry.google_scholar_id %}
{% assign entry_has_google_scholar_badge = true %}
{% endif %}

{% assign entry_has_openalex_badge = false %}
{% if entry.openalex_id %}
{% assign entry_has_openalex_badge = true %}
{% endif %}

{% assign entry_has_plumx_badge = false %}
{% if entry.doi %}
{% assign entry_has_plumx_badge = true %}
{% endif %}

{% assign entry_has_inspirehep_badge = false %}
{% if entry.inspirehep_id %}
{% assign entry_has_inspirehep_badge = true %}
{% endif %}
{% if entry_has_altmetric_badge or entry_has_dimensions_badge or entry_has_google_scholar_badge or entry_has_inspirehep_badge %}
{% if entry_has_altmetric_badge
or entry_has_dimensions_badge
or entry_has_google_scholar_badge
or entry_has_openalex_badge
or entry_has_plumx_badge
or entry_has_inspirehep_badge
%}
<div class="badges d-inline-flex align-items-center" style="gap:0.35rem;">
{% if site.enable_publication_badges.altmetric and entry_has_altmetric_badge %}
<span
class="altmetric-embed"
data-badge-type="2"
data-badge-popover="right"
data-hide-no-mentions="true"
{% if entry.altmetric != blank and entry.altmetric != 'true' %}
data-altmetric-id="{{ entry.altmetric }}"
{% elsif entry.arxiv %}
Expand All @@ -293,7 +314,21 @@
{% endif %}
></span>
{% endif %}
{% if entry.abstract != blank %}
{% if entry_has_openalex_badge %}
{% capture openalex_api_url %}https://api.openalex.org/works/{{ entry.openalex_id }}?select=cited_by_count{% endcapture %}
<a
class="openalex-badge"
href="https://openalex.org/works/{{ entry.openalex_id }}"
Comment on lines +318 to +321
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Normalize OpenAlex IDs before composing badge URLs

The new OpenAlex badge code assumes entry.openalex_id is only the short key (for example W123...) and blindly prepends https://api.openalex.org/works/ and https://openalex.org/works/. If a bibliography entry stores the canonical OpenAlex ID format (https://openalex.org/W...), both the API URL and destination URL become malformed (double-prefixed), so the badge image and link break for that publication.

Useful? React with 👍 / 👎.

aria-label="OpenAlex link"
role="button"
>
<img
src="https://img.shields.io/badge/dynamic/json?url={{ openalex_api_url | url_encode }}&query=$.cited_by_count&label=OpenAlex&color=2f7f6f&labelColor=beige"
alt="OpenAlex citation count"
>
</a>
{% endif %}
{% if site.enable_publication_badges.dimensions and entry_has_dimensions_badge %}
<span
class="__dimensions_badge_embed__"
{% if entry.doi %}
Expand Down Expand Up @@ -335,7 +370,7 @@
>
</a>
{% endif %}
{% if entry.doi %}
{% if site.enable_publication_badges.plumx and entry_has_plumx_badge %}
<a
href="https://plu.mx/a/?doi={{ entry.doi }}"
aria-label="PlumX Metrics Detail Page"
Expand Down
44 changes: 0 additions & 44 deletions assets/js/publication-badges.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,49 +31,6 @@
badges.prepend(badge);
};

const getOpenAlexUiUrl = (workId) => workId.replace("https://api.openalex.org/", "https://openalex.org/");

const fetchOpenAlexWork = async (apiUrl) => {
try {
const response = await fetch(apiUrl);
if (!response.ok) return null;

const work = await response.json();
return work.id && Number.isFinite(work.cited_by_count) ? work : null;
} catch {
return null;
}
};

const addOpenAlexBadge = async (badges, doi) => {
if (badges.querySelector(".openalex-badge")) return;

const apiUrl = `https://api.openalex.org/works/https://doi.org/${doi}?select=id,cited_by_count`;
const work = await fetchOpenAlexWork(apiUrl);
if (!work) return;

const link = document.createElement("a");
link.className = "openalex-badge";
link.href = getOpenAlexUiUrl(work.id);
link.setAttribute("aria-label", "OpenAlex link");
link.setAttribute("role", "button");
link.rel = "external nofollow noopener";
link.target = "_blank";

const image = document.createElement("img");
image.src = `https://img.shields.io/badge/OpenAlex-${work.cited_by_count}-2f7f6f?labelColor=beige`;
image.alt = `${work.cited_by_count} OpenAlex citations`;

link.appendChild(image);

const plumxBadge = badges.querySelector(".plumx-plum-print-popup");
if (plumxBadge) {
badges.insertBefore(link, plumxBadge);
} else {
badges.appendChild(link);
}
};

document.querySelectorAll(".bibliography li > .row > [id]").forEach((entry) => {
const doi = getDoi(entry);
if (!doi) return;
Expand All @@ -82,6 +39,5 @@
if (!badges) return;

addAltmetricBadge(badges, doi);
addOpenAlexBadge(badges, doi);
});
})();
Loading