documentation/fix-link.sh
2025-02-28 09:46:43 +07:00

29 lines
904 B
Bash
Executable File

#!/bin/bash
INPUT_FILE="$1"
if [[ ! -f "$INPUT_FILE" ]]; then
echo "Error: Input file does not exist."
exit 1
fi
while IFS=':' read -r file_path line_err status desc data; do
# Trim whitespace from variables
file_path="$(echo "$file_path" | xargs)"
line_err="$(echo "$line_err" | xargs)"
status="$(echo "$status" | xargs)"
desc="$(echo "$desc" | xargs)"
data="$(echo "$data" | xargs | tr -d "'")" # Remove quotes from data
if [[ -f "$file_path" ]]; then
if [[ "$desc" == "undefined label" ]]; then
fixed_data="$(echo "$data" | tr '\\/_' '-')"
sed -i "s@$data@$fixed_data@g" "$file_path"
elif [[ "$desc" == *"toctree contains reference to nonexisting document"* ]]; then
fixed_data="$(echo "$data" | tr '\\/_' '-')"
sed -i "s@$data@$fixed_data@g" "$file_path"
fi
fi
done < "$INPUT_FILE"