-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-docs.sh
More file actions
executable file
·69 lines (58 loc) · 1.92 KB
/
build-docs.sh
File metadata and controls
executable file
·69 lines (58 loc) · 1.92 KB
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
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
set -eu
die () { echo "ERROR: $*" >&2; exit 2; }
for cmd in pdoc3; do
command -v "$cmd" >/dev/null ||
die "Missing $cmd; \`pip install $cmd\`"
done
out="www/doc"
package="sambo"
echo
echo 'Building API reference docs'
echo
pdoc3 --html --force \
--template-dir ".github/pdoc_template" \
--output-dir "$out" \
"$package"
ANALYTICS1="<script async src='https://www.googletagmanager.com/gtag/js?id=G-QJH7PLMB12'></script><script>window.dataLayer=window.dataLayer||[];function gtag(){dataLayer.push(arguments);}gtag('js',new Date());gtag('config','G-QJH7PLMB12');</script>"
ANALYTICS2='<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-2900001379782823" crossorigin></script>'
find "$out" -name '*.html' -print0 |
xargs -0 -- sed -i "s#</head>#$ANALYTICS1$ANALYTICS2</head>#i"
exit 0 # TODO: For now
echo
echo 'Testing for broken links'
echo
problematic_urls='
https://www.gnu.org/licenses/agpl-3.0.html
'
pushd "$out" >/dev/null
grep -PR '<a .*?href=' |
sed -E "s/:.*?<a .*?href=([\"'])(.*?)/\t\2/g" |
tr "\"'" '#' |
cut -d'#' -f1 |
sort -u -t$'\t' -k 2 |
sort -u |
python -c '
import sys
from urllib.parse import urljoin
for line in sys.stdin.readlines():
base, url = line.split("\t")
print(base, urljoin(base, url.strip()), sep="\t")
' |
grep -v $'\t''$' |
while read -r line; do
while IFS=$'\t' read -r file url; do
echo "$file: $url"
[ -f "$url" ] ||
curl --silent --fail --retry 3 --retry-delay 1 --connect-timeout 10 \
--user-agent 'Mozilla/5.0 Firefox 125' "$url" >/dev/null 2>&1 ||
grep -qF "$url" <(echo "$problematic_urls") ||
die "broken link in $file: $url"
done
done
popd >/dev/null
echo
echo "All good. Docs in: $out"
echo
echo " file://$(readlink -f "$out")/$package/index.html"
echo