Skip to content

Commit 37d77af

Browse files
committed
Update convert-images.yml
1 parent 99f2c9f commit 37d77af

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

.github/workflows/convert-images.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ jobs:
2424
id: convert
2525
run: |
2626
changed=false
27+
sed_script="$(mktemp)"
2728
2829
while IFS= read -r -d '' f; do
2930
[ -f "$f" ] || continue
@@ -38,15 +39,21 @@ jobs:
3839
rel_dst="${outfile#static}"
3940
# Escape regex metacharacters (. [ \ * ^ $) in the source path
4041
esc_src="$(printf '%s\n' "$rel_src" | sed 's/[.[\*^$]/\\&/g')"
41-
find content -name "*.md" \
42-
-exec sed -i "s|${esc_src}|${rel_dst}|gI" {} +
42+
# Accumulate substitutions; apply in one pass after the loop
43+
printf 's|%s|%s|gI\n' "$esc_src" "$rel_dst" >> "$sed_script"
4344
changed=true
4445
echo "Converted: $f"
4546
else
4647
echo "Failed to convert: $f, skipping." >&2
4748
fi
4849
done < <(find static/images -type f \( -iname "*.png" -o -iname "*.jpg" -o -iname "*.jpeg" \) -print0)
4950
51+
# Single pass over all markdown files with all substitutions at once
52+
if [ "$changed" = "true" ]; then
53+
find content -name "*.md" -exec sed -i -f "$sed_script" {} +
54+
fi
55+
rm -f "$sed_script"
56+
5057
echo "changed=$changed" >> "$GITHUB_OUTPUT"
5158
5259
- name: Commit converted images

0 commit comments

Comments
 (0)