19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
+
-
-
+
+
-
-
-
-
+
+
+
+
|
# Ensure directory exists
if [[ ! -d "${base_dir}" ]]; then
echo "[$(date +'%Y-%m-%dT%H:%M:%S%z')]: ${base_dir} not a directory!" >&2
exit 1
fi
# Root folder: remove leading / from href and src attributes
# Works across (and preserves) line breaks introduced by the `tidy` command
sed -i '' -- 's/href=\"\//href=\"/g' "${base_dir}"*.html
sed -i '' -- 's/src=\"\//src=\"/g' "${base_dir}"*.html
perl -0777 -i -pe 's/ href=(\s*)"\// href=$1"/ig' "${base_dir}"*.html
perl -0777 -i -pe 's/ src=(\s*)"\// src=$1"/ig' "${base_dir}"*.html
# subfolders: replace leading / with ../ in href and src attributes
sed -i '' -- 's/href=\"\//href=\"..\//g' "${base_dir}"articles/*.html
sed -i '' -- 's/src=\"\//src=\"..\//g' "${base_dir}"articles/*.html
sed -i '' -- 's/href=\"\//href=\"..\//g' "${base_dir}"series/*.html
sed -i '' -- 's/src=\"\//src=\"..\//g' "${base_dir}"series/*.html
perl -0777 -i -pe 's/ href=(\s*)"\// href=$1"..\//ig' "${base_dir}"articles/*.html
perl -0777 -i -pe 's/ src=(\s*)"\// src=$1"..\//ig' "${base_dir}"articles/*.html
perl -0777 -i -pe 's/ href=(\s*)"\// href=$1"..\//ig' "${base_dir}"series/*.html
perl -0777 -i -pe 's/ src=(\s*)"\// src=$1"..\//ig' "${base_dir}"series/*.html
|