mirror of
https://git.sr.ht/~seirdy/seirdy.one
synced 2024-12-26 10:22:10 +00:00
b44a4ead71
FeedValidator was fixed upstream; it doesn't use an allowlist of (X)HTML
attributes anymore. After updating FeedValidator to the latest commit, I
don't need to filter out false-positives for these attributes.
The FeedValidator commit that resolved the issue:
0b130bd5d7
80 lines
1.6 KiB
Bash
Executable file
80 lines
1.6 KiB
Bash
Executable file
#!/usr/bin/env dash
|
|
|
|
set -u
|
|
|
|
# the name of this program
|
|
progname="$(basename "${0}")"
|
|
|
|
help_text="Usage: ${progname} [options...] URL
|
|
|
|
Validate the given feed URL, excluding false-positives
|
|
|
|
Options:
|
|
-h Print this help and exit
|
|
"
|
|
|
|
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
|
|
}
|
|
|
|
while getopts "ho" flags; do
|
|
case ${flags} in
|
|
h)
|
|
usage
|
|
exit 0
|
|
;;
|
|
*)
|
|
bad_option "${flags}" 'invalid option'
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|
|
|
|
url="$1"
|
|
|
|
|
|
find_rel_mention_count() {
|
|
curl -s "$url" | grep -cF 'rel="mentioned"'
|
|
}
|
|
|
|
rel_mention_count="$(find_rel_mention_count)"
|
|
|
|
run_validator() {
|
|
"$GHQ_ROOT/github.com/w3c/feedvalidator/src/demo.py" "$url"
|
|
}
|
|
|
|
validate_feed() {
|
|
rel_mention_string="Unregistered link relationship \($rel_mention_count occurrence"
|
|
if [ "$rel_mention_count" = '1' ]; then
|
|
rel_mention_string="Unregistered link relationship"
|
|
fi
|
|
|
|
# silence "self reference doesn't match" because i'm testing a localhost copy.
|
|
# 'should not contian" has a false positive triggered by ARIA
|
|
# entries with the same timestamp isn't a big deal
|
|
# unregistered link relationship is a false positive caused by an unknown namespace.
|
|
full_regex="Use of unknown namespace|Self reference doesn't match|$rel_mention_string|entries with the same value|Validating $url"
|
|
|
|
run_validator \
|
|
| grep -Ev "$full_regex"
|
|
}
|
|
|
|
validator_output="$(validate_feed)"
|
|
if [ "$validator_output" = '' ]; then
|
|
echo "Feed is valid"
|
|
exit 0
|
|
else
|
|
echo "Feed errors found!" 1>&2
|
|
echo "$validator_output"
|
|
exit 1
|
|
fi
|
|
|
|
# vi:ft=sh
|