fix: image path

This commit is contained in:
Gal 2025-02-24 07:48:15 +01:00
parent 8e5e121f29
commit 71b8147a05
Signed by: gal
GPG Key ID: F035BC65003BC00B
1 changed files with 22 additions and 0 deletions

View File

@ -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: