#!/usr/bin/env python3 """Generate README.md from index.json.""" import json from pathlib import Path DIR = Path(__file__).parent data = json.loads((DIR / "index.json").read_text(encoding="utf-8")) def sort_key(s): """OFFICIAL first, then BETA, then by stars desc, then name asc.""" return ( 0 if s.get("official") else 1, 0 if s.get("beta") else 1, -s.get("stars", 0), s["name"] ) lines = [] w = lines.append w((DIR / "header.md").read_text(encoding="utf-8").rstrip()) # --- TOC --- categories = sorted(set(s["category"] for s in data["servers"])) w("") for cat in categories: anchor = cat.lower().replace(" ", "-").replace("(", "").replace(")", "") w(f"- [{cat}](#{anchor})") for cat in categories: servers = sorted((s for s in data["servers"] if s["category"] == cat), key=sort_key) w("") w(f"## {cat}") w("") for s in servers: badge = "" if s.get("official"): badge = " ![OFFICIAL](badges/official.svg)" elif s.get("beta"): badge = " ![BETA](badges/beta.svg)" note = s.get("note", "") w(f'- [{s["name"]}]({s["url"]}){badge} — {s["description"]}') details = [f"⭐ {s['stars']}"] c = s.get("contributors") if c: details.append(f"{c} Contributors") if note: details.append(note) w(f' {" · ".join(details)}') # --- Footer --- w("") w((DIR / "footer.md").read_text(encoding="utf-8").rstrip()) (DIR / "README.md").write_text("\n".join(lines) + "\n", encoding="utf-8") print("README.md generated from index.json")