tvalidate.sh - monochromatic - monochromatic blog: http://blog.z3bra.org
(HTM) git clone git://z3bra.org/monochromatic
(DIR) Log
(DIR) Files
(DIR) Refs
---
tvalidate.sh (947B)
---
1 #!/bin/sh
2
3 w3c() {
4 type=$1
5 file=$2
6
7 case $type in
8 html) curl -si \
9 -F "uploaded_file=@$file;text/html" \
10 -F uri-doctype=HTML5 \
11 https://validator.w3.org/check \
12 | grep -i ^x-w3c-validator-status:
13 ;;
14 css) curl -si \
15 -F "file=@$file" \
16 -F profile=css3 \
17 https://jigsaw.w3.org/css-validator/validator \
18 | grep -i ^x-w3c-validator-status:
19 ;;
20 rss) curl -si \
21 --data-urlencode "rawdata=$(< $file tr -d '\n\t')" \
22 --data "manual=1" \
23 https://validator.w3.org/feed/check.cgi \
24 | grep -o 'Valid RSS' \
25 ;;
26 esac | dos2unix | grep -o Valid | head -n1
27 }
28
29 case $1 in
30 rss) pattern='*.xml' ;;
31 css) pattern='*.css' ;;
32 html) pattern='*.html' ;;
33 *)
34 $0 rss
35 $0 css
36 $0 html
37 ;;
38 esac
39
40 # empty pattern won't match anything
41 for file in $(find . -name "$pattern"); do
42 printf '[%4s] %s' "$1" "${file#./}"
43 val="$(w3c $1 $file)"
44 case $val in
45 Valid) printf "\r[ OK ]\n" ;;
46 *) printf "\r[FAIL]\n" ;;
47 esac
48 done
49
50 exit 0