forked from Amplitude-Developer-Docs/amplitude-dev-center
-
Notifications
You must be signed in to change notification settings - Fork 0
/
linkchecker
executable file
·41 lines (37 loc) · 1.29 KB
/
linkchecker
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
#!/bin/bash
# Rebuild the site
mkdocs build
# Run the link checker on the local site
if [ "$1" = "external" ]; then
# Also check external links. Requires additional filtering
exec 5>&1
echo "Running full link check, including external links. This may take some time..."
out=$( npx -y broken-link-checker-local@latest ./site -rog \
--exclude 'https://help.amplitude.com' \
--exclude 'https://api.amplitude.com' \
--exclude 'https://api2.ampliude.com' \
--exclude 'https://amplitude.com/api' \
--exclude 'https://analytics.eu.amplitude.com/api/' \
--exclude 'https://help.adjust.com/' \
--exclude 'https://forum.unity.com/' \
| grep --line-buffered 'BROKEN\|Getting links from' \
| grep --line-buffered -v 'HTTP_403\|HTTP_308\|HTTP_401\|HTTP_400' \
| tee >(cat - >&5) )
else
# Check only internal links
exec 5>&1
echo "Running internal link check..."
out=$( npx -y broken-link-checker-local@latest ./site -roe \
| grep --line-buffered 'BROKEN\|Getting links from' \
| tee >(cat - >&5) )
fi
# Count broken links
fail_count=$(echo "$out" | grep -o BROKEN | wc -l)
echo "Found $fail_count broken links."
# Fail if greater than 0 broken links
if [[ $fail_count -gt 0 ]]
then
exit 1
else
exit 0
fi