documentation/fix-link.sh

29 lines
904 B
Bash
Raw Normal View History

2025-02-28 08:38:23 +07:00
#!/bin/bash
2025-02-28 09:46:43 +07:00
INPUT_FILE="$1"
2025-02-28 08:38:23 +07:00
2025-02-28 09:46:43 +07:00
if [[ ! -f "$INPUT_FILE" ]]; then
echo "Error: Input file does not exist."
2025-02-28 08:38:23 +07:00
exit 1
fi
2025-02-28 09:46:43 +07:00
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
2025-02-28 08:38:23 +07:00
fi
2025-02-28 09:46:43 +07:00
done < "$INPUT_FILE"