File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments