diff --git a/scripts/publish.py b/scripts/publish.py index 2fe87cc..4afebaf 100755 --- a/scripts/publish.py +++ b/scripts/publish.py @@ -66,6 +66,17 @@ def extract_image_references(content: str) -> Set[str]: def find_image_in_source(image_ref: str, source_dir: Path) -> Union[Path, None]: """Find an image file in the source directory.""" + # First try exact path relative to source_dir + full_path = source_dir / image_ref + if full_path.exists(): + if full_path.is_symlink(): + resolved = full_path.resolve() + if resolved.is_file(): + return resolved + elif full_path.is_file(): + return full_path + + # If exact path doesn't work, try finding by filename image_name = Path(image_ref).name # Search for the image recursively, following symlinks @@ -76,6 +87,17 @@ def find_image_in_source(image_ref: str, source_dir: Path) -> Union[Path, None]: return resolved_path elif path.is_file(): return path + + # If still not found, try searching with spaces replaced by hyphens + image_name_alt = image_name.replace(' ', '-') + for path in source_dir.rglob(image_name_alt): + if path.is_symlink(): + resolved_path = path.resolve() + if resolved_path.is_file(): + return resolved_path + elif path.is_file(): + return path + return None def process_images(content: str, source_dir: Path, dest_dir: Path) -> str: