fix(romhacks): only link library files that exist on disk
handoff.json lists files captured at routing time, but the extraction-cruft cleanup later removes files extracted out of a kept archive. The Caddy file_server can only serve real files (not archive interiors), so existence-filter the art + guide rel-paths against library/<slug>/ before embedding/linking them — dropping phantom entries that would 404.
This commit is contained in:
@@ -39,6 +39,17 @@ def load_handoff(slug):
|
||||
return {}
|
||||
|
||||
|
||||
def on_disk(slug, rels):
|
||||
"""Keep only the rel paths that actually exist under library/<slug>/.
|
||||
|
||||
The handoff record lists files captured at routing time, but the
|
||||
extraction-cruft cleanup later removes files extracted out of a kept
|
||||
archive — so a guide can be in handoff.json yet gone from disk (and the
|
||||
file_server can only serve real files, not archive interiors)."""
|
||||
base = LIBRARY / slug
|
||||
return [rel for rel in rels if (base / rel).exists()]
|
||||
|
||||
|
||||
def pick_guides(guides, artifact):
|
||||
"""Filter the raw handoff guide list to linkable docs/spreadsheets/extras.
|
||||
|
||||
@@ -152,10 +163,11 @@ def render(r):
|
||||
# Box art — embed from the internal Caddy file-server. Fall back to art
|
||||
# filenames in the metadata folder if the handoff record is missing them.
|
||||
ho = load_handoff(r["slug"])
|
||||
art = ho.get("art") or []
|
||||
art = on_disk(r["slug"], ho.get("art") or [])
|
||||
if not art and (META / r["slug"]).exists():
|
||||
art = sorted(p.name for p in (META / r["slug"]).glob("*")
|
||||
if p.suffix.lower() in (".png", ".jpg", ".jpeg", ".webp", ".gif"))
|
||||
cand = sorted(p.name for p in (META / r["slug"]).glob("*")
|
||||
if p.suffix.lower() in (".png", ".jpg", ".jpeg", ".webp", ".gif"))
|
||||
art = on_disk(r["slug"], cand) # only those also present in the served library
|
||||
for a in art:
|
||||
fm.append(f"})")
|
||||
if art:
|
||||
@@ -171,7 +183,7 @@ def render(r):
|
||||
if links:
|
||||
fm += ["## Download", ""] + [f"- {l}" for l in links] + [""]
|
||||
# Guides / spreadsheets / extras — link each to the served file.
|
||||
guides = pick_guides(ho.get("guides", []), r["artifact"])
|
||||
guides = pick_guides(on_disk(r["slug"], ho.get("guides", [])), r["artifact"])
|
||||
if guides:
|
||||
fm += ["## Guides & extras", ""]
|
||||
for rel in guides[:MAX_GUIDES]:
|
||||
|
||||
Reference in New Issue
Block a user