From 0b9a33b4a307cf8d62ab92109bca91c0fc7a1c8c Mon Sep 17 00:00:00 2001 From: systemreliability <51009183+systemreliability@users.noreply.github.com> Date: Sun, 3 May 2026 00:25:05 +0200 Subject: [PATCH 1/2] Refine publication badge ordering and links --- assets/js/publication-badges.js | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/assets/js/publication-badges.js b/assets/js/publication-badges.js index c0845790..3998cf28 100644 --- a/assets/js/publication-badges.js +++ b/assets/js/publication-badges.js @@ -26,17 +26,32 @@ badge.className = "altmetric-embed"; badge.dataset.badgeType = "2"; badge.dataset.badgePopover = "right"; + badge.dataset.hideNoMentions = "true"; badge.dataset.doi = doi; badges.prepend(badge); }; + const getOpenAlexUiUrl = (workId) => workId.replace("https://api.openalex.org/", "https://openalex.org/"); + + const resolveOpenAlexLink = async (link, apiUrl) => { + try { + const response = await fetch(apiUrl); + if (!response.ok) return; + + const work = await response.json(); + if (work.id) link.href = getOpenAlexUiUrl(work.id); + } catch { + // Keep the DOI fallback if OpenAlex lookup is unavailable. + } + }; + const addOpenAlexBadge = (badges, doi) => { if (badges.querySelector(".openalex-badge")) return; - const apiUrl = `https://api.openalex.org/works/https://doi.org/${doi}?select=cited_by_count`; + const apiUrl = `https://api.openalex.org/works/https://doi.org/${doi}?select=id,cited_by_count`; const link = document.createElement("a"); link.className = "openalex-badge"; - link.href = `https://openalex.org/search?q=${encodeURIComponent(`doi:${doi}`)}`; + link.href = `https://doi.org/${doi}`; link.setAttribute("aria-label", "OpenAlex link"); link.setAttribute("role", "button"); link.rel = "external nofollow noopener"; @@ -49,7 +64,15 @@ image.alt = "OpenAlex citation count"; link.appendChild(image); - badges.appendChild(link); + + const plumxBadge = badges.querySelector(".plumx-plum-print-popup"); + if (plumxBadge) { + badges.insertBefore(link, plumxBadge); + } else { + badges.appendChild(link); + } + + resolveOpenAlexLink(link, apiUrl); }; document.querySelectorAll(".bibliography li > .row > [id]").forEach((entry) => { From 0e28839cf47be15e1e34ecfb2327f67d852dc138 Mon Sep 17 00:00:00 2001 From: systemreliability <51009183+systemreliability@users.noreply.github.com> Date: Sun, 3 May 2026 00:35:24 +0200 Subject: [PATCH 2/2] Hide OpenAlex badges for missing works --- assets/js/publication-badges.js | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/assets/js/publication-badges.js b/assets/js/publication-badges.js index 3998cf28..5b7d1348 100644 --- a/assets/js/publication-badges.js +++ b/assets/js/publication-badges.js @@ -33,35 +33,36 @@ const getOpenAlexUiUrl = (workId) => workId.replace("https://api.openalex.org/", "https://openalex.org/"); - const resolveOpenAlexLink = async (link, apiUrl) => { + const fetchOpenAlexWork = async (apiUrl) => { try { const response = await fetch(apiUrl); - if (!response.ok) return; + if (!response.ok) return null; const work = await response.json(); - if (work.id) link.href = getOpenAlexUiUrl(work.id); + return work.id && Number.isFinite(work.cited_by_count) ? work : null; } catch { - // Keep the DOI fallback if OpenAlex lookup is unavailable. + return null; } }; - const addOpenAlexBadge = (badges, doi) => { + 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 = `https://doi.org/${doi}`; + 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/dynamic/json?url=${encodeURIComponent( - apiUrl - )}&query=$.cited_by_count&label=OpenAlex&color=2f7f6f&labelColor=beige`; - image.alt = "OpenAlex citation count"; + 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); @@ -71,8 +72,6 @@ } else { badges.appendChild(link); } - - resolveOpenAlexLink(link, apiUrl); }; document.querySelectorAll(".bibliography li > .row > [id]").forEach((entry) => {