fix: modify publish symbolic link

This commit is contained in:
Gal 2025-02-23 23:50:26 +01:00
parent 98d4db67ea
commit 8e5e121f29
Signed by: gal
GPG Key ID: F035BC65003BC00B
1 changed files with 12 additions and 6 deletions

View File

@ -5,7 +5,7 @@ import shutil
import sys
from pathlib import Path
import re
from typing import Set, Dict
from typing import Set, Dict, Union
import logging
from datetime import datetime
from dotenv import load_dotenv
@ -45,7 +45,7 @@ def load_env_vars() -> tuple[Path, Path]:
return Path(source_dir), Path(dest_dir)
def get_publish_status(file_path: Path) -> bool | None:
def get_publish_status(file_path: Path) -> Union[bool, None]:
"""Check if a markdown file has publish: true/false in its frontmatter."""
try:
with open(file_path, 'r', encoding='utf-8') as f:
@ -64,13 +64,17 @@ def extract_image_references(content: str) -> Set[str]:
markdown_images = set(re.findall(r'!\[.*?\]\((.*?)\)', content))
return obsidian_images.union(markdown_images)
def find_image_in_source(image_ref: str, source_dir: Path) -> Path | None:
def find_image_in_source(image_ref: str, source_dir: Path) -> Union[Path, None]:
"""Find an image file in the source directory."""
image_name = Path(image_ref).name
# Search for the image recursively
# Search for the image recursively, following symlinks
for path in source_dir.rglob(image_name):
if path.is_file():
if path.is_symlink():
resolved_path = path.resolve()
if resolved_path.is_file():
return resolved_path
elif path.is_file():
return path
return None
@ -127,7 +131,9 @@ def sync_files(source_dir: Path, dest_dir: Path, clean: bool = False):
# Process markdown files
for source_file in source_dir.rglob("*.md"):
publish_status = get_publish_status(source_file)
# Resolve symbolic links
actual_file = source_file.resolve() if source_file.is_symlink() else source_file
publish_status = get_publish_status(actual_file)
if publish_status is None:
continue