1
0
Fork 0
mirror of https://git.sr.ht/~seirdy/seirdy.one synced 2024-11-27 14:12:09 +00:00
seirdy.one/scripts/bin/check-whole-site
2023-11-15 02:31:06 -08:00

72 lines
1.8 KiB
Bash
Executable file

#!/usr/bin/env dash
set -e -u
# the name of this program
progname="$(basename "${0}")"
help_text="Usage: $progname [OPTIONS...] [BASEURL]
Validate the site's markup, CSS, and accessibility.
Uses xmllint to to check well-formedness and the Nu HTML Checker to
check (X)HTML5 and CSS validity on every markup file (inc. HTML, XHTML,
SVG). (xmllint is only relevant if you're using XML syntax).
Lints source CSS files with stylelint.
Uses both axe-core and the IBM Equal Access Checker to test
accessibility on every page in the sitemap.
Options:
-h Print this help and exit
-j Max parallel jobs. Default: 2
"
# TODO: add the following:
# - validate JSON schema (web app manifest, webfinger)
usage() {
printf '%s' "${help_text}"
}
# when the user passess bad args, send a msg to stderr and exit
# usage: bad_option <option> <reason>
bad_option() {
echo "${progname}: option ${1}: ${2}" >&2
usage >&2
exit 1
}
jobs='2'
while getopts "hj" flags; do
case ${flags} in
h)
usage
exit 0
;;
j)
jobs="$1"
shift
;;
*)
bad_option "${flags}" 'invalid option'
;;
esac
done
base_url="${1-http://localhost:8089}"
# HTML validation is already parallelized, so run that single-threaded.
make -j1 HUGO_FLAGS=-DF HUGO_BASEURL="$base_url" clean hugo xhtmlize copy-to-xhtml validate-html
sitemap_links="$(curl -sSL --compressed "$base_url/sitemap.xml" | htmlq loc -t)"
urls_offline="$(echo "$sitemap_links" | rg -v '/search/$' | tr '\n' ' ')"
make -j "$jobs" -f Makefile.online HUGO_BASEURL="$base_url" all-extra URLS="$urls_offline" &
make deploy-staging RSYNCFLAGS_EXTRA=-q
urls_online="$(echo "$sitemap_links" | rg -v '/(?:search|wcag-is-a-starting-point)/$' | sort | tr '\n' ' ')"
make -f Makefile.online hint-online URLS="$urls_online"
wait
# TODO: run lighthouse on every page in the sitemap.
# vi:ft=sh