MakerFLOSS/scripts/mkdocs_hooks.py
sjat b9722f082f
All checks were successful
Build docs site / build (push) Successful in 30s
Build slides / build (push) Successful in 51s
feat(docs): render Specs table on each hardware host page
- Add scripts/mkdocs_hooks.py: on_page_markdown hook that prepends
  `# {hostname}` + a Specs table built from the YAML frontmatter.
  Reuses fmt_cpu/fmt_ram/fmt_storage/fmt_nic from gen_overview.py so
  the host page and the index table stay in sync.
- Wire the hook into mkdocs.yml.
- Demote `# Notes` / `# ToDo` to `##` in the five host source files so
  each rendered page has a single H1.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-18 15:24:56 +02:00

34 lines
1.1 KiB
Python

"""MkDocs build hook: render a Specs section on each hardware host page from its YAML frontmatter."""
from __future__ import annotations
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent))
from gen_overview import fmt_cpu, fmt_nic, fmt_ram, fmt_storage # noqa: E402
def _render_specs(meta: dict) -> str:
rows = [
("Model", meta.get("model")),
("Location", meta.get("location")),
("CPU", fmt_cpu(meta)),
("RAM", fmt_ram(meta)),
("Storage", fmt_storage(meta)),
("NIC", fmt_nic(meta)),
("Status", meta.get("status")),
]
lines = ["| Field | Value |", "|---|---|"]
for label, value in rows:
if not value:
continue
lines.append(f"| {label} | {value} |")
return "\n".join(lines)
def on_page_markdown(markdown, page, config, files): # noqa: ARG001
meta = page.meta or {}
hostname = meta.get("hostname")
if not hostname:
return markdown
return f"# {hostname}\n\n## Specs\n\n{_render_specs(meta)}\n\n{markdown}"