Write a human-readable Markdown mirror for a wiki node.
(node: Dict[str, Any])
| 254 | |
| 255 | |
| 256 | def write_node_mirror(node: Dict[str, Any]) -> str: |
| 257 | """Write a human-readable Markdown mirror for a wiki node.""" |
| 258 | relative_path = node.get("file_path") or _relative_file_path( |
| 259 | node["user_id"], |
| 260 | node["node_type"], |
| 261 | node["node_id"], |
| 262 | ) |
| 263 | output_path = _wiki_root() / relative_path |
| 264 | output_path.parent.mkdir(parents=True, exist_ok=True) |
| 265 | |
| 266 | metadata = node.get("metadata") or _json_loads(node.get("metadata_json")) |
| 267 | lines = [ |
| 268 | "---", |
| 269 | f"node_id: {node['node_id']}", |
| 270 | f"user_id: {node['user_id']}", |
| 271 | f"node_type: {node['node_type']}", |
| 272 | f"updated_at: {node.get('updated_at') or _now()}", |
| 273 | "---", |
| 274 | "", |
| 275 | f"# {node['title']}", |
| 276 | "", |
| 277 | ] |
| 278 | keywords = str(node.get("keywords") or "").strip() |
| 279 | if keywords: |
| 280 | lines.extend([f"Keywords: {keywords}", ""]) |
| 281 | if metadata: |
| 282 | lines.extend(["## Metadata", "", "```json", json.dumps(metadata, ensure_ascii=False, indent=2), "```", ""]) |
| 283 | lines.extend(["## Body", "", str(node.get("body") or "").strip(), ""]) |
| 284 | output_path.write_text("\n".join(lines), encoding="utf-8") |
| 285 | return relative_path |
| 286 | |
| 287 | |
| 288 | def upsert_node( |
no test coverage detected