fix: review fixes for generate_site.py

This commit is contained in:
Abdessamad Derraz
2026-03-18 10:39:23 +01:00
parent 0b1ed3cb1a
commit 32e4f6e580
2 changed files with 24 additions and 15 deletions

1
.gitignore vendored
View File

@@ -17,6 +17,7 @@ docs/platforms/
docs/systems/ docs/systems/
docs/emulators/ docs/emulators/
docs/contributing.md docs/contributing.md
docs/gaps.md
# Large files stored as GitHub Release assets (> 50MB) # Large files stored as GitHub Release assets (> 50MB)
bios/Arcade/Arcade/Firmware.19.0.0.zip bios/Arcade/Arcade/Firmware.19.0.0.zip

View File

@@ -14,6 +14,7 @@ from __future__ import annotations
import argparse import argparse
import json import json
import os import os
import shutil
import sys import sys
from datetime import datetime, timezone from datetime import datetime, timezone
from pathlib import Path from pathlib import Path
@@ -174,7 +175,8 @@ def generate_platform_index(coverages: dict) -> str:
for name, cov in sorted(coverages.items(), key=lambda x: x[1]["platform"]): for name, cov in sorted(coverages.items(), key=lambda x: x[1]["platform"]):
display = cov["platform"] display = cov["platform"]
pct = _pct(cov["present"], cov["total"]) pct = _pct(cov["present"], cov["total"])
status = _status_icon(cov["percentage"]) plat_status = cov["config"].get("status", "active")
status = "archived" if plat_status == "archived" else _status_icon(cov["percentage"])
lines.append( lines.append(
f"| [{display}]({name}.md) | " f"| [{display}]({name}.md) | "
f"{cov['present']}/{cov['total']} ({pct}) | " f"{cov['present']}/{cov['total']} ({pct}) | "
@@ -349,8 +351,8 @@ def generate_emulators_index(profiles: dict) -> str:
lines = [ lines = [
"# Emulators", "# Emulators",
"", "",
"| Engine | Type | Systems | Files | Gaps |", "| Engine | Type | Systems | Files |",
"|--------|------|---------|-------|------|", "|--------|------|---------|-------|",
] ]
unique = {k: v for k, v in profiles.items() if v.get("type") != "alias"} unique = {k: v for k, v in profiles.items() if v.get("type") != "alias"}
@@ -368,7 +370,7 @@ def generate_emulators_index(profiles: dict) -> str:
lines.append( lines.append(
f"| [{emu_name}]({name}.md) | {emu_type} | " f"| [{emu_name}]({name}.md) | {emu_type} | "
f"{sys_str} | {len(files)} | |" f"{sys_str} | {len(files)} |"
) )
if aliases: if aliases:
@@ -491,11 +493,10 @@ def generate_gap_analysis(
if not files: if not files:
continue continue
systems = profile.get("systems", []) # Collect all files declared by any platform (global check)
all_platform_names = set() all_platform_names = set()
for sys_id in systems: for pfiles in platform_files.values():
for pname, pfiles in platform_files.items(): all_platform_names.update(pfiles)
all_platform_names.update(pfiles)
undeclared = [] undeclared = []
for f in files: for f in files:
@@ -701,7 +702,6 @@ def main():
for d in GENERATED_DIRS: for d in GENERATED_DIRS:
target = docs / d target = docs / d
if target.exists(): if target.exists():
import shutil
shutil.rmtree(target) shutil.rmtree(target)
# Ensure output dirs # Ensure output dirs
@@ -721,8 +721,8 @@ def main():
cov = _compute_coverage(name, args.platforms_dir, db) cov = _compute_coverage(name, args.platforms_dir, db)
coverages[name] = cov coverages[name] = cov
print(f" {cov['platform']}: {cov['present']}/{cov['total']} ({_pct(cov['present'], cov['total'])})") print(f" {cov['platform']}: {cov['present']}/{cov['total']} ({_pct(cov['present'], cov['total'])})")
except (FileNotFoundError, KeyError) as e: except FileNotFoundError as e:
print(f" {name}: skipped ({e})") print(f" {name}: skipped ({e})", file=sys.stderr)
# Load emulator profiles # Load emulator profiles
print("Loading emulator profiles...") print("Loading emulator profiles...")
@@ -770,19 +770,27 @@ def main():
print("Generating contributing page...") print("Generating contributing page...")
(docs / "contributing.md").write_text(generate_contributing()) (docs / "contributing.md").write_text(generate_contributing())
# Update mkdocs.yml nav # Update mkdocs.yml nav section only (avoid yaml.dump round-trip mangling quotes)
print("Updating mkdocs.yml nav...") print("Updating mkdocs.yml nav...")
nav = generate_mkdocs_nav(coverages, manufacturers, profiles)
nav_yaml = yaml.dump({"nav": nav}, default_flow_style=False, sort_keys=False, allow_unicode=True)
with open("mkdocs.yml") as f: with open("mkdocs.yml") as f:
mkconfig = yaml.safe_load(f) content = f.read()
mkconfig["nav"] = generate_mkdocs_nav(coverages, manufacturers, profiles) # Replace or append nav section
if "\nnav:" in content:
content = content[:content.index("\nnav:") + 1] + nav_yaml
else:
content += "\n" + nav_yaml
with open("mkdocs.yml", "w") as f: with open("mkdocs.yml", "w") as f:
yaml.dump(mkconfig, f, default_flow_style=False, sort_keys=False, allow_unicode=True) f.write(content)
total_pages = ( total_pages = (
1 # home 1 # home
+ 1 + len(coverages) # platform index + detail + 1 + len(coverages) # platform index + detail
+ 1 + len(manufacturers) # system index + detail + 1 + len(manufacturers) # system index + detail
+ 1 + len(profiles) # emulator index + detail + 1 + len(profiles) # emulator index + detail
+ 1 # gap analysis
+ 1 # contributing + 1 # contributing
) )
print(f"\nGenerated {total_pages} pages in {args.docs_dir}/") print(f"\nGenerated {total_pages} pages in {args.docs_dir}/")