|
47 | 47 |
|
48 | 48 | # Process image references line by line for more reliable detection
|
49 | 49 | while IFS= read -r line; do
|
50 |
| - # Fix the regex syntax for bash |
| 50 | + # Check for Markdown style image references |
51 | 51 | if [[ "$line" =~ !\[(.*)\]\((.*)\) ]]; then
|
52 | 52 | img_path="${BASH_REMATCH[2]}"
|
53 | 53 |
|
|
56 | 56 | continue
|
57 | 57 | fi
|
58 | 58 |
|
59 |
| - # Determine the absolute path of the image |
| 59 | + # Handle Markdown image syntax |
60 | 60 | if [[ $img_path == /* ]]; then
|
61 | 61 | # Absolute path within repository
|
62 | 62 | abs_img_path="./$img_path"
|
|
87 | 87 | echo "Files in $base_dir:"
|
88 | 88 | ls -la "$base_dir"
|
89 | 89 | fi
|
| 90 | + # Check for HTML style image tags - look for <img tags and extract src attribute |
| 91 | + elif [[ "$line" =~ \<img[[:space:]][^>]*src=\"([^\"]+)\"[^>]*\> ]]; then |
| 92 | + img_path="${BASH_REMATCH[1]}" |
| 93 | + |
| 94 | + # Skip URLs |
| 95 | + if [[ $img_path == http* ]]; then |
| 96 | + continue |
| 97 | + fi |
| 98 | + |
| 99 | + # Determine the absolute path of the image |
| 100 | + if [[ $img_path == /* ]]; then |
| 101 | + # Absolute path within repository |
| 102 | + abs_img_path="./$img_path" |
| 103 | + else |
| 104 | + # Relative path to the README |
| 105 | + abs_img_path="$base_dir/$img_path" |
| 106 | + fi |
| 107 | + |
| 108 | + # Extract just the filename |
| 109 | + img_filename=$(basename "$img_path") |
| 110 | + wiki_img_path="images/$img_filename" |
| 111 | + |
| 112 | + # Copy the image to wiki repository if it exists |
| 113 | + if [ -f "$abs_img_path" ]; then |
| 114 | + echo "Copying image: $abs_img_path -> ./wiki/$wiki_img_path" |
| 115 | + cp -v "$abs_img_path" "./wiki/$wiki_img_path" || echo "Error copying image" |
| 116 | + |
| 117 | + # Escape special characters in the path for sed |
| 118 | + escaped_img_path=$(echo "$img_path" | sed 's/[\/&]/\\&/g') |
| 119 | + |
| 120 | + # Replace the HTML image reference in content |
| 121 | + content=$(echo "$content" | sed "s|src=\"$escaped_img_path\"|src=\"$wiki_img_path\"|g") |
| 122 | + echo "Replaced HTML image reference: $img_path → $wiki_img_path" |
| 123 | + else |
| 124 | + echo "Warning: HTML image file not found: $abs_img_path" |
| 125 | + # Add more debug info |
| 126 | + echo "Current directory: $(pwd)" |
| 127 | + echo "Files in $base_dir:" |
| 128 | + ls -la "$base_dir" |
| 129 | + fi |
90 | 130 | fi
|
91 | 131 | done < "./$rel_path"
|
92 | 132 |
|
|
0 commit comments