1
0
Fork 0
mirror of https://git.sr.ht/~seirdy/seirdy.one synced 2024-09-19 20:02:10 +00:00

Run Nu HTML Checker with both HTML and XML parsers

Requires silencing an HTML-only error that isn't actually an error, but
a hint that doesn't apply to polygot markup (warns against trailing
slashes which aren't a problem if you always use quotes).
This commit is contained in:
Rohan Kumar 2023-11-25 13:32:55 -08:00
parent 2e10fce294
commit 6c9a8a9b20
No known key found for this signature in database
GPG key ID: 1E892DB2A5F84479
2 changed files with 25 additions and 12 deletions

View file

@ -1,26 +1,27 @@
# Filter false positives from the .messages entry of Nu Validator output # Filter false positives from the .messages entry of Nu Validator output
.messages |= map( .messages |= map(
. | select( . | select(
.type == "info" and (
.message == "Trailing slash on void elements has no effect and interacts badly with unquoted attribute values."
and (.url | test(".html"))
) or
.type == "error" and ( .type == "error" and (
( # See https://github.com/w3c/css-validator/issues/361
.message == "CSS: Parse Error."
and .extract == "){outline:none}}@media(prefers"
and .hiliteLength == 1
)
or
( # See https://github.com/validator/validator/issues/1166 ( # See https://github.com/validator/validator/issues/1166
# This false-positive has been fixed; will remove once validator.nu updates # This false-positive has been fixed; will remove once validator.nu updates
# validator.w3.org/nu is up-to-date. # validator.w3.org/nu is up-to-date.
.message == "Attribute “media” not allowed on element “meta” at this point." .message == "Attribute “media” not allowed on element “meta” at this point."
and (.extract | test(" name=\"theme-color\"")) and (.extract | test(" name=\"theme-color\""))
) ) or
or
( # see https://github.com/w3c/css-validator/issues/369 ( # see https://github.com/w3c/css-validator/issues/369
.message == "CSS: “contain-intrinsic-size”: Property “contain-intrinsic-size” doesn't exist." .message == "CSS: “contain-intrinsic-size”: Property “contain-intrinsic-size” doesn't exist."
) ) or
or
( # see https://github.com/w3c/css-validator/issues/370 ( # see https://github.com/w3c/css-validator/issues/370
.message == "CSS: “contain”: “inline-size” is not a “contain” value." .message == "CSS: “contain”: “inline-size” is not a “contain” value."
) or
( # See https://github.com/w3c/css-validator/issues/361
.message == "CSS: Parse Error."
and .extract == "){outline:none}}@media(prefers"
and .hiliteLength == 1
) )
) | not ) | not
) )

View file

@ -1,16 +1,28 @@
#!/bin/sh #!/bin/sh
# Runs the Nu HTML checker (assumed to be available on your $PATH as `vnu`) on all pages.
#shellcheck disable=SC3040 # This only sets pipefail if it's available and otherwise does nothing
set -o pipefail 2>/dev/null || true
set -e -u set -e -u
dirname="$(dirname "$0")" dirname="$(dirname "$0")"
output_dir="$1" output_dir="$1"
# List all HTML, XHTML, and SVG files we wish to check.
# We test both XHTML and HTML files, despite the fact that they are identical, because we want to validate under both an HTML and XML parser. VNU has some HTML-only checks.
find_files_to_analyze() { find_files_to_analyze() {
find "$output_dir" -type f -name '*.xhtml' -o -name '*.svg' \ find "$output_dir" -type f -name '*.html' -o -name '*.xhtml' -o -name '*.svg' \
| grep -Ev '(bimi\.svg|search/index\.x?html)$' | grep -Ev '(bimi\.svg|search/index\.x?html)$'
} }
# Force a non-zero exit code for vnu. We'll decide the exit status after filtering out false-posives.
vnu_nofail() {
xargs vnu --stdout --format json --also-check-svg || true
}
# files_to_analyze="$(find_files_to_analyze)" # files_to_analyze="$(find_files_to_analyze)"
# we skip the BIMI icon (VNU can't handle SVG 1.2) and the search page (it has raw templates). # we skip the BIMI icon (VNU can't handle SVG 1.2) and the search page (it has raw templates).
find_files_to_analyze \ find_files_to_analyze \
| xargs vnu --stdout --format json --also-check-svg \ | vnu_nofail \
| sh "$dirname/filter-vnu.sh" | sh "$dirname/filter-vnu.sh"