|
| 1 | +#!/bin/bash |
| 2 | +set -eu |
| 3 | + |
| 4 | +die () { echo "ERROR: $*" >&2; exit 2; } |
| 5 | + |
| 6 | +for cmd in pdoc3; do |
| 7 | + command -v "$cmd" >/dev/null || |
| 8 | + die "Missing $cmd; \`pip install $cmd\`" |
| 9 | +done |
| 10 | + |
| 11 | +out="www/doc" |
| 12 | +package="sambo" |
| 13 | + |
| 14 | + |
| 15 | +echo |
| 16 | +echo 'Building API reference docs' |
| 17 | +echo |
| 18 | +pdoc3 --html --force \ |
| 19 | + --template-dir ".github/pdoc_template" \ |
| 20 | + --output-dir "$out" \ |
| 21 | + "$package" |
| 22 | + |
| 23 | + |
| 24 | +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>" |
| 25 | +ANALYTICS2='<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-2900001379782823" crossorigin></script>' |
| 26 | +find "$out" -name '*.html' -print0 | |
| 27 | + xargs -0 -- sed -i "s#</head>#$ANALYTICS1$ANALYTICS2</head>#i" |
| 28 | + |
| 29 | +exit 0 # TODO: For now |
| 30 | + |
| 31 | +echo |
| 32 | +echo 'Testing for broken links' |
| 33 | +echo |
| 34 | +problematic_urls=' |
| 35 | +https://www.gnu.org/licenses/agpl-3.0.html |
| 36 | +' |
| 37 | +pushd "$out" >/dev/null |
| 38 | +grep -PR '<a .*?href=' | |
| 39 | + sed -E "s/:.*?<a .*?href=([\"'])(.*?)/\t\2/g" | |
| 40 | + tr "\"'" '#' | |
| 41 | + cut -d'#' -f1 | |
| 42 | + sort -u -t$'\t' -k 2 | |
| 43 | + sort -u | |
| 44 | + python -c ' |
| 45 | +import sys |
| 46 | +from urllib.parse import urljoin |
| 47 | +for line in sys.stdin.readlines(): |
| 48 | + base, url = line.split("\t") |
| 49 | + print(base, urljoin(base, url.strip()), sep="\t") |
| 50 | + ' | |
| 51 | + grep -v $'\t''$' | |
| 52 | + while read -r line; do |
| 53 | + while IFS=$'\t' read -r file url; do |
| 54 | + echo "$file: $url" |
| 55 | + [ -f "$url" ] || |
| 56 | + curl --silent --fail --retry 3 --retry-delay 1 --connect-timeout 10 \ |
| 57 | + --user-agent 'Mozilla/5.0 Firefox 125' "$url" >/dev/null 2>&1 || |
| 58 | + grep -qF "$url" <(echo "$problematic_urls") || |
| 59 | + die "broken link in $file: $url" |
| 60 | + done |
| 61 | + done |
| 62 | +popd >/dev/null |
| 63 | + |
| 64 | + |
| 65 | +echo |
| 66 | +echo "All good. Docs in: $out" |
| 67 | +echo |
| 68 | +echo " file://$(readlink -f "$out")/$package/index.html" |
| 69 | +echo |
0 commit comments