-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
105 lines (85 loc) · 2.88 KB
/
main.py
File metadata and controls
105 lines (85 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
from __future__ import annotations
from pathlib import Path
from typing import Any, Dict, List, Optional
import yaml
def _load_yaml(path: Path) -> Dict[str, Any]:
if not path.exists():
raise FileNotFoundError(f"Missing data file: {path}")
with path.open("r", encoding="utf-8") as f:
return yaml.safe_load(f) or {}
def define_env(env):
"""
MkDocs Macros entrypoint.
"""
# --- Load module registry once ---
data_path = Path(env.project_dir) / "docs" / "assets" / "edia_modules_info.yml"
registry = _load_yaml(data_path).get("modules", {})
def _get_module(key: str) -> Dict[str, Any]:
if key not in registry:
known = ", ".join(sorted(registry.keys()))
raise KeyError(f"Unknown EDIA module key '{key}'. Known keys: {known}")
return registry[key]
# ----------------------------
# Macro API
# ----------------------------
@env.macro
def edia(
key: str,
*,
version: Optional[str] = None,
text: Optional[str] = None,
target_blank: bool = True,
) -> str:
"""
Render a single EDIA module link with icon + label + optional version.
Usage:
{{ edia("eye") }}
{{ edia("eye", version="0.2") }}
{{ edia("eye", text="Custom Label") }}
"""
m = _get_module(key)
name = text or m["name"]
icon = m["icon"]
url = m["url"]
version_final = version or m.get("default_version")
# Build display label
suffix_parts = []
if version_final:
suffix_parts.append(f"{version_final}")
suffix = f" [{' • '.join(suffix_parts)}]" if suffix_parts else ""
# mkdocs-material emoji/icon syntax:
# [:icon-name: Label](url){:target="_blank"}
attrs = '{:target="_blank"}' if target_blank else ""
return f"[:{icon}: {name}{suffix}]({url}){attrs}"
@env.macro
def edia_list(
keys: List[str],
*,
version: Optional[str] = None,
) -> str:
"""
Render a bullet list of EDIA modules.
Usage:
{{ edia_list(["core","eye","eye_vive"]) }}
"""
lines = [f"- {edia(k, version=version)}" for k in keys]
return "\n".join(lines)
@env.macro
def edia_inline(
keys: List[str],
*,
sep: str = " · ",
version: Optional[str] = None,
) -> str:
"""
Render an inline sequence of module links.
Usage:
{{ edia_inline(["core","eye"]) }}
"""
return sep.join(edia(k, version=version) for k in keys)
@env.macro
def edia_modules() -> List[str]:
"""
Return known module keys (useful for debugging / docs).
"""
return sorted(registry.keys())