-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
verify-doc-links.sh
executable file
·58 lines (48 loc) · 1.15 KB
/
verify-doc-links.sh
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash
set -e
PWD=`pwd`
GOOD_LINKS=()
BAD_LINKS=()
verify_local_file() {
# echo "${PWD}${1}"
if [ -e "${PWD}${1}" ]; then
GOOD_LINKS+=("$1")
echo -e "\033[92mok\033[0m $1"
else
BAD_LINKS+=("$1")
echo -e "\033[91mmissing\033[0m $1"
fi
}
verify_url() {
if curl -L --output /dev/null --silent --head --fail $1; then
GOOD_LINKS+=("$1")
echo -e "\033[92mok\033[0m $1"
else
BAD_LINKS+=("$1")
echo -e "\033[91mmissing\033[0m $1"
fi
}
echo -e "\033[93mGathering links in docs...\033[0m"
FILES=`find docs | grep .md$`
for f in ${FILES[@]};
do
echo -e "\033[1m$f\033[0m"
# Get all the URLs out of markdown links in the form of [alt text](url)
LINKS=`grep -o -E "\[.*?\]\(.+?\)" "${f}" | sed -e 's/\[.*\](\(.*\))/\1/' | sed -e 's/#[^#]*$//'`
for link in ${LINKS[@]};
do
if [[ $link =~ ^/ ]]; then
verify_local_file $link
fi
if [[ $link =~ ^http ]]; then
verify_url $link
fi
done
echo
done
if [ -z "${BAD_LINKS}" ]; then
echo -e "\033[92mAll links ok\033[0m $1"
else
echo -e "\033[91mFound ${#BAD_LINKS[@]} bad links!\033[0m $1"
exit 1
fi