Skip to content

Commit 7d16c11

Browse files
committed
Meir robust handtering av manglande bilete
1 parent b05d9c2 commit 7d16c11

File tree

1 file changed

+38
-5
lines changed

1 file changed

+38
-5
lines changed

.github/workflows/docsygen.yml

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,18 @@ jobs:
116116
src_path="$mdfile_dir/$img_path"
117117
fi
118118
119-
# Copy the image if it exists
119+
# Copy the image if it exists, create placeholder if not
120120
if [ -f "$src_path" ]; then
121121
# Get just the filename for destination
122122
img_filename=$(basename "$img_path")
123123
cp "$src_path" "$slidev_dir/images/$img_filename"
124124
echo "Copied: $src_path → $slidev_dir/images/$img_filename"
125125
else
126126
echo "WARNING: Image not found: $src_path (referenced as: $img_path)"
127+
# Create a placeholder text file that can be referenced
128+
img_filename=$(basename "$img_path")
129+
echo "🖼️ IMAGE MISSING: $img_path" > "$slidev_dir/images/missing-${img_filename%.png}.txt"
130+
echo "Created placeholder for missing image: $img_filename"
127131
fi
128132
fi
129133
done
@@ -157,10 +161,39 @@ jobs:
157161
echo "=== Step 2 - After header conversion ==="
158162
grep "images/" "$slidev_dir/step2.md" || echo "No images found"
159163
160-
# Normalize all image paths to ./images/filename since we copied all images there
161-
# Handle markdown images: ![alt](any/path/file.ext) -> ![alt](./images/file.ext)
162-
# Handle YAML images: image: any/path/file.ext -> image: ./images/file.ext
163-
sed 's|!\[\([^]]*\)\](\([^/]*/\)*\([^/)]*\.\(png\|jpg\|jpeg\|gif\|svg\|webp\))\)|![\1](./images/\3)|g; s|image: \([^/]*/\)*\([^/]*\.\(png\|jpg\|jpeg\|gif\|svg\|webp\)\)|image: ./images/\2|g' "$slidev_dir/step2.md" > "$slidev_dir/step3.md"
164+
# Normalize all image paths and handle missing images
165+
# First, normalize existing images to ./images/filename
166+
sed 's|!\[\([^]]*\)\](\([^/]*/\)*\([^/)]*\.\(png\|jpg\|jpeg\|gif\|svg\|webp\))\)|![\1](./images/\3)|g; s|image: \([^/]*/\)*\([^/]*\.\(png\|jpg\|jpeg\|gif\|svg\|webp\)\)|image: ./images/\2|g' "$slidev_dir/step2.md" > "$slidev_dir/step3_temp.md"
167+
168+
# Then, replace references to missing images with error messages
169+
while IFS= read -r line; do
170+
if echo "$line" | grep -q '!\[.*\](./images/.*\)'; then
171+
# Extract image filename from markdown
172+
img_file=$(echo "$line" | sed -n 's/.*!\[.*\](\.\/images\/\([^)]*\)).*/\1/p')
173+
if [ -n "$img_file" ] && [ ! -f "$slidev_dir/images/$img_file" ]; then
174+
# Image is missing, replace with error message
175+
alt_text=$(echo "$line" | sed -n 's/.*!\[\([^]]*\)\].*/\1/p')
176+
echo "$line" | sed "s|!\[.*\](./images/.*)|**🚫 MISSING IMAGE: $img_file** *(was: $alt_text)*|g"
177+
else
178+
echo "$line"
179+
fi
180+
elif echo "$line" | grep -q 'image: ./images/'; then
181+
# Extract image filename from YAML
182+
img_file=$(echo "$line" | sed -n 's/.*image: \.\/images\/\([^[:space:]]*\).*/\1/p')
183+
if [ -n "$img_file" ] && [ ! -f "$slidev_dir/images/$img_file" ]; then
184+
# Image is missing, comment out the line and add error
185+
echo "# MISSING IMAGE: $img_file"
186+
echo "# $line"
187+
else
188+
echo "$line"
189+
fi
190+
else
191+
echo "$line"
192+
fi
193+
done < "$slidev_dir/step3_temp.md" > "$slidev_dir/step3.md"
194+
195+
# Clean up temp file
196+
rm -f "$slidev_dir/step3_temp.md"
164197
echo "=== Step 3 - After image path conversion ==="
165198
grep "images/" "$slidev_dir/step3.md" || echo "No images found"
166199

0 commit comments

Comments
 (0)