Skip to content
Merged
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
41 changes: 30 additions & 11 deletions scripts/generate_entry_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'<a href="{esc(url)}" target="_blank" rel="noopener">{esc(s)}</a>'
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'<a href="{esc(url)}" target="_blank" rel="noopener">{esc(tok)}</a>')
elif tok:
parts.append(esc(tok))
return ", ".join(parts) if parts else esc(val)


def _fmt_languages(val: str) -> str:
Expand Down Expand Up @@ -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'<tr><td>{esc(h.get("changed_at",""))}</td>'
f'<td class="field">{esc(h.get("field_name",""))}</td>'
f'<td class="muted">{_linkify_value(h["previous_value"]) if h.get("previous_value") else "—"}</td>'
f'<td class="muted">{_linkify_value(h["previous_value"])}</td>'
f'<td>{_linkify_value(h["value"]) if h.get("value") else "—"}</td>'
f'<td><code>{esc(h.get("source_id","—"))}</code></td></tr>'
)
Expand Down
Loading