-
Notifications
You must be signed in to change notification settings - Fork 1
/
link-check
executable file
·27 lines (26 loc) · 985 Bytes
/
link-check
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/bin/bash
# check the validity of relative and hard links in all the md files
while read -rd '' -r file; do
echo "Checking file: $file"
grep -Eno '\[[^]]+\]([^)]+))' "$file" | while read -r line; do
line_link="$(echo "$line" | grep -oP '(?<=\().*(?=\))')"
echo -n " - $(echo "$line" | cut -d: -f1): $line_link "
case "$line_link" in
http*)
if [[ "$(curl -o /dev/null -Isw '%{http_code}\n' "$line_link")" == "200" ]]; then
echo -e "\033[32m[ OK ]\e[0m"
else
echo -e "\033[31m[ ERROR ]\e[0m" && exit 1
fi
;;
*)
if [[ -e "$(dirname "$file")/$line_link" ]]; then
echo -e "\033[32m[ OK ]\e[0m"
else
echo -e "\033[31m[ ERROR ]\e[0m" && exit 1
fi
;;
esac
done
done < <(find . -type f -name '*.md' -print0)
exit 0