From 242cf4e8dc16689ba58b34a8b1a1e0d57f62d0ac Mon Sep 17 00:00:00 2001 From: priyanka <21082240+priya-gitTest@users.noreply.github.com> Date: Tue, 1 Dec 2026 20:45:45 +0100 Subject: [PATCH] fix(entry): link comma-list DOIs/HF ids, strip DOI version suffix; change-history shows only real deviations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two entry-page display bugs (verified on biomni + 3d-slicer): - Discovered DOIs/HF ids that are comma-lists (e.g. two HF ids) or carry a preprint version suffix (biorxiv/arxiv v1) rendered as plain text or a dead link. Now each token links, and the DOI href drops the v suffix so it resolves. - Change history listed every FIRST-harvest value as a 'change' (Was —, Now X), duplicating the lineage table. Now it shows only rows with a real previous_value; otherwise 'no deviations yet'. --- scripts/generate_entry_pages.py | 41 ++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/scripts/generate_entry_pages.py b/scripts/generate_entry_pages.py index 341b908..bf4eba7 100644 --- a/scripts/generate_entry_pages.py +++ b/scripts/generate_entry_pages.py @@ -94,15 +94,30 @@ def _linkify_value(val: str) -> str: } +def _doi_for_url(token: str) -> str: + """Strip a trailing preprint version suffix (bioRxiv/arXiv 'v1', 'v2', ...) + so the DOI resolves — doi.org rejects '10.1101/....656746v1'. The displayed + text keeps the original token; only the href is cleaned.""" + return re.sub(r"v\d+$", "", token) + + def _registry_link(field_name: str, val: str) -> str: - """Link a discovered package / DOI value to its registry page. Only a single - clean token is linked (no commas/spaces), so a comma-list stays plain text.""" - s = str(val).strip() + """Link each discovered package / HF id / DOI to its registry page. Handles a + comma-separated list (e.g. two HF ids, several DOIs) by linking each token; + a token with a space or quote stays plain text (no broken href).""" tmpl = _REGISTRY_URL.get(field_name) - if tmpl and s and " " not in s and "," not in s and '"' not in s: - url = tmpl.format(s) - return f'{esc(s)}' - return esc(val) + if not tmpl: + return esc(val) + parts = [] + for raw in str(val).split(","): + tok = raw.strip() + if tok and " " not in tok and '"' not in tok: + href_tok = _doi_for_url(tok) if field_name == "discovered_doi" else tok + url = tmpl.format(href_tok) + parts.append(f'{esc(tok)}') + elif tok: + parts.append(esc(tok)) + return ", ".join(parts) if parts else esc(val) def _fmt_languages(val: str) -> str: @@ -524,14 +539,18 @@ def _notfound_phrase(field_name: str) -> str: else: lineage = "" - # Change history / deviations - if history: + # Change history / deviations. A "change" means a value DIFFERED from a prior + # run — i.e. there is a real previous_value. First-harvest records (no previous + # value) are not changes; they already appear in the lineage table above, so + # showing them here as "Was — / Now X" is misleading. Keep only real changes. + real_changes = [h for h in (history or []) if h.get("previous_value") not in (None, "")] + if real_changes: hrows = [] - for h in history: + for h in real_changes: hrows.append( f'{esc(h.get("changed_at",""))}' f'{esc(h.get("field_name",""))}' - f'{_linkify_value(h["previous_value"]) if h.get("previous_value") else "—"}' + f'{_linkify_value(h["previous_value"])}' f'{_linkify_value(h["value"]) if h.get("value") else "—"}' f'{esc(h.get("source_id","—"))}' )