()
| 32 | |
| 33 | |
| 34 | def main() -> None: |
| 35 | args = parser().parse_args() |
| 36 | record = maybe_load_json_record(args.input) or {} |
| 37 | title = args.title or str(record.get("title", "")).strip() |
| 38 | if not title: |
| 39 | raise SystemExit("materialize_figure_asset.py requires --title or metadata with a title.") |
| 40 | |
| 41 | config = runtime_config() |
| 42 | if args.vault: |
| 43 | config["obsidian_vault"] = args.vault |
| 44 | resolved_subdir = resolve_domain_subdir( |
| 45 | config, |
| 46 | title=title, |
| 47 | abstract=str(record.get("abstract", "")), |
| 48 | subdir=args.subdir, |
| 49 | ) |
| 50 | |
| 51 | note_path = resolve_obsidian_note_path( |
| 52 | config, |
| 53 | title=title, |
| 54 | subdir=resolved_subdir, |
| 55 | filename=args.filename, |
| 56 | ) |
| 57 | source_image = Path(args.source_image).expanduser().resolve() |
| 58 | if not source_image.exists(): |
| 59 | raise SystemExit(f"Source image does not exist: {source_image}") |
| 60 | |
| 61 | asset_dir = note_path.parent / args.asset_subdir |
| 62 | asset_dir.mkdir(parents=True, exist_ok=True) |
| 63 | dest_image = asset_dir / source_image.name |
| 64 | shutil.copy2(source_image, dest_image) |
| 65 | |
| 66 | output_mode, root_root = resolve_note_output_mode(config) |
| 67 | relative_from_note = dest_image.relative_to(note_path.parent) |
| 68 | relative_markdown_embed = f"})" |
| 69 | absolute_markdown_embed = f"" |
| 70 | |
| 71 | payload = { |
| 72 | "status": "ok", |
| 73 | "script": "materialize_figure_asset.py", |
| 74 | "title": title, |
| 75 | "note_path": str(note_path), |
| 76 | "source_image": str(source_image), |
| 77 | "dest_image_path": str(dest_image), |
| 78 | "absolute_markdown_embed": absolute_markdown_embed, |
| 79 | "relative_markdown_embed": relative_markdown_embed, |
| 80 | "label": args.label, |
| 81 | "output_mode": output_mode, |
| 82 | "subdir": resolved_subdir, |
| 83 | } |
| 84 | |
| 85 | if output_mode == "obsidian": |
| 86 | vault_relative = dest_image.relative_to(root_root) |
| 87 | payload["vault_relative_image_path"] = vault_relative.as_posix() |
| 88 | payload["obsidian_embed"] = f"![[{vault_relative.as_posix()}]]" |
| 89 | emit(payload, args.output) |
| 90 | |
| 91 |
no test coverage detected