Skip to content

Instantly share code, notes, and snippets.

@Dpbm
Created April 30, 2025 17:51
Show Gist options
  • Save Dpbm/6ddf1843c66872c5f3ce83835db9e9e4 to your computer and use it in GitHub Desktop.
Save Dpbm/6ddf1843c66872c5f3ce83835db9e9e4 to your computer and use it in GitHub Desktop.
fixing public images paths in nextjs
#!/bin/bash
files=$(grep -Eo "image_[0-9]+\.png" ./app/content/**/post.mdx)
for i in $files; do
split=$(echo $i | tr ":" "\n")
FILE=""
IMAGE=""
counter=0
for j in $split; do
if [ $counter -eq 0 ]; then
FILE=$j
else
IMAGE=$j
fi
counter=$(( $counter + 1 ))
done
sed -i -E "s|$IMAGE|/image/$IMAGE|g" "$FILE"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment