Skip to content

Commit

Permalink
Add script to fix relative links and image sources
Browse files Browse the repository at this point in the history
  • Loading branch information
Tony Wasserka committed Sep 23, 2024
1 parent 9224571 commit 9728478
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions 03_fix_image_refs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

shopt -s globstar
CONTENTROOT=`realpath .`/content
echo $CONTENTROOT
for i in content/**/*.md
do
echo $i

# Make HTML links and image sources relative to the root
PREFIX=`realpath --relative-to=$i $CONTENTROOT`

perl -0777 -i -pe 's,href="((?![/\.])(?!http).*)",href="'"$PREFIX"'/\1",g' $i

perl -0777 -i -pe 's,src="((?![/\.]).*)",src="'"$PREFIX"'/\1",g' $i
done

0 comments on commit 9728478

Please sign in to comment.