35 lines
1.1 KiB
Python
35 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}"
|