news-digest: separated SOURCE / REDDIT THREAD action chips + archive page

Two requested polish items:

1. Reddit items now show TWO distinct action chips in the footer:

     [↗ SOURCE huggingface.co]  [⌥ REDDIT THREAD]      3h · u/foo

   Previously the external link was a tiny dot-separated text link
   that visually competed with the post metadata. Now: explicit
   labeled buttons, distinct colors (cyan for source, blue for
   thread), with hover states that match the Australis accent
   palette. Non-Reddit items get just the SOURCE chip.

2. Archive page at /archive.html — lists every edition-*.html on
   disk, newest-first, sorted PM-before-AM within a day. Each row
   is the date in editorial serif + an AM/PM chip color-coded
   (yellow morning / cyan evening) + a hover-affordance arrow.
   Header link from the main edition reads "ARCHIVE →".

   Generation: digest.py walks OUTPUT_DIR for the edition-*.html
   filename pattern on every run, sorts, renders archive.html.j2,
   writes atomically. Cheap (~1ms even with hundreds of editions).
   No retention cap — twice-daily for a year is ~700 small files,
   well under any reasonable concern.

CSS additions: .action chip styles (with per-action color variants),
.archive-link in masthead, full .archive-row + .archive-edition
treatment.
This commit is contained in:
vh
2026-04-26 13:48:58 -07:00
parent b3d20f2a1a
commit 28cb96c087
4 changed files with 285 additions and 29 deletions
+48
View File
@@ -353,6 +353,54 @@ def write_output(html: str, generated_at: datetime) -> None:
index_tmp.write_text(html, encoding="utf-8")
index_tmp.rename(index)
log(f"wrote {index} (and archive {archive.name})")
write_archive_index(generated_at)
ARCHIVE_FNAME_RE = re.compile(r"^edition-(\d{4}-\d{2}-\d{2})-(am|pm)\.html$")
def write_archive_index(generated_at: datetime) -> None:
"""Render /output/archive.html — list every edition-*.html in
OUTPUT_DIR, newest-first. Cheap (re-runs every digest fire);
template loads from the same TEMPLATE_DIR."""
editions = []
for p in OUTPUT_DIR.glob("edition-*.html"):
m = ARCHIVE_FNAME_RE.match(p.name)
if not m:
continue
date_str, ed = m.group(1), m.group(2)
try:
date = datetime.strptime(date_str, "%Y-%m-%d").date()
except ValueError:
continue
editions.append({
"filename": p.name,
"date": date,
"edition": "morning" if ed == "am" else "evening",
"edition_short": ed.upper(),
"date_long": date.strftime("%A %B %-d, %Y"),
# Sort key: date descending, then PM before AM (within a day,
# PM is the most recent edition).
"_sort": (date, 1 if ed == "pm" else 0),
})
editions.sort(key=lambda e: e["_sort"], reverse=True)
env = Environment(
loader=FileSystemLoader(str(TEMPLATE_DIR)),
autoescape=select_autoescape(["html"]),
trim_blocks=True,
lstrip_blocks=True,
)
tpl = env.get_template("archive.html.j2")
html = tpl.render(
editions=editions,
generated_at=generated_at,
total=len(editions),
)
out = OUTPUT_DIR / "archive.html"
out_tmp = out.with_suffix(".html.tmp")
out_tmp.write_text(html, encoding="utf-8")
out_tmp.rename(out)
log(f"wrote {out} ({len(editions)} editions indexed)")
# ── main ─────────────────────────────────────────────────────────────