commit: edd8762039b7f8f4ee5eb70c9d94d26d6db184b6
parent: c7a0db1781f7a043d25542e42a4eb3d789ec869a
author: Chris Noxz <chris@noxz.tech>
date: Thu, 30 Dec 2021 10:55:13 +0100
fix redundant parent traversing in relative links
2 files changed, 27 insertions(+), 9 deletions(-)
diff --git a/build b/build
@@ -718,20 +718,38 @@ main() {
cp -r "git.${1}" "${1}/git"
# translate git.site to site/git
- find "${1}/git" -type f -name "*.html" | while read -r line; do
- sed -i "s,\"//\[site\]/,\"//[site]/git/,g" "$line"
- sed -i "s,\"//git.${1}/,\"//${1}/git/,g" "$line"
- sed -i "s,https://git.${1}/,https://${1}/git/,g" "$line"
- sed -i "s,\"//\[root\]/,\"//[site]/,g" "$line"
+ print_loading "Translate git site into ./git"
+ find "${1}/git" -type f -name "*.html" | while read -r file; do
+ sed -i "s,\"//\[site\]/,\"//[site]/git/,g" "$file"
+ sed -i "s,\"//git.${1}/,\"//${1}/git/,g" "$file"
+ sed -i "s,https://git.${1}/,https://${1}/git/,g" "$file"
+ sed -i "s,\"//\[root\]/,\"//[site]/,g" "$file"
done
+ print_done
# convert absolute paths to relative, so that they work with IPFS
print_loading "Converting absolute paths to relative"
- find "${1}" -type f -name "*.html" | while read -r line; do
- count="$(echo "$line" | tr -cd '/' | wc -c)"
+ find "${1}" -type f -name "*.html" | while read -r file; do
+ count="$(echo "$file" | tr -cd '/' | wc -c)"
sed -i "s,\"//\(${1}\|\[site\]\)/,\"$(
seq -f "../%g" -s '' 2 "$count" | sed 's/[0-9]//g'
- ),g" "$line"
+ ),g" "$file"
+
+ # remove redundant prefix from references
+ grep -o '="../[^"]*"' "$file" \
+ | sed -e 's/^="//g' -e 's/"$//g' | while read -r path; do
+ rel="$(realpath --relative-to="${file%/*}" "${file%/*}/${path}")"
+ rel="$(echo $rel | sed \
+ -e 's/\./\\./g' \
+ -e 's/\&/\\&/g' \
+ )"
+ ref="$(echo $path | sed \
+ -e 's/\./\\./g' \
+ -e 's/\&/\\&/g' \
+ )"
+ sed "s,=\"$ref\",=\"$rel\",g" -i "$file"
+ done
+
done
print_done
diff --git a/publish b/publish
@@ -10,7 +10,7 @@ if [ $? -eq 0 ]; then
echo "Are you sure [y/N]?"
read response
case "$response" in
- [yY][eE][sS]|[yY]) rsync -v -a --delete-after "${tmpdir}/" "${2}" ;;
+ [yY][eE][sS]|[yY]) rsync -v -a --no-perms --delete-after "${tmpdir}/" "${2}" ;;
*) return ;;
esac
fi