tChange check.sh script to validate local files - monochromatic - monochromatic blog: http://blog.z3bra.org
(HTM) git clone git://z3bra.org/monochromatic
(DIR) Log
(DIR) Files
(DIR) Refs
---
(DIR) commit 6979f19f2a9236e133ced41522d39bb29318b5ec
(DIR) parent f8766d5669e5570414c488539899c2cd61727fb1
(HTM) Author: Willy Goiffon <wgoiffon@LPWGF01.centro.fr>
Date: Mon, 23 Dec 2019 10:45:26 +0100
Change check.sh script to validate local files
check.sh used to verify the currently deployed website. This new version
will now upload the local files to validate them BEFORE they are deployed.
Diffstat:
M Makefile | 6 +++---
D check.sh | 75 -------------------------------
A validate.sh | 50 +++++++++++++++++++++++++++++++
3 files changed, 53 insertions(+), 78 deletions(-)
---
(DIR) diff --git a/Makefile b/Makefile
t@@ -12,15 +12,15 @@ install: $(NAME).tbz
tar -xjf $(NAME).tbz -C $(PREFIX)
check: $(PAGES)
- @./check.sh
+ @./validate.sh every damn thing about this blog
clean:
rm -f $(PAGES) $(FEEDS) $(NAME).tbz
.SUFFIXES: .txt .html .xml
-HEADER = head.html
-FOOTER = foot.html
+HEADER = header.tmpl
+FOOTER = footer.tmpl
$(FEEDS): index.txt
@echo "RSSGEN $@"
(DIR) diff --git a/check.sh b/check.sh
t@@ -1,75 +0,0 @@
-#!/bin/bash
-
-uri=blog.z3bra.org
-charset=utf-8
-doctype=Inline
-profile=css3
-
-function w3c_valid () {
- if (curl -sI "$1" | grep -o 'Invalid' >/dev/null); then
- echo -e "[\033[1;31mFAIL\033[0m]"
- echo -e " Errors : $1"
- exit 1
- fi
-}
-
-function rss_valid () {
- if (curl -s "$1" | grep -o 'Sorry' >/dev/null); then
- echo -e "[\033[1;31mFAIL\033[0m]"
- echo -e " Errors : $1"
- exit 1
- fi
-}
-
-
-# HTML files
-check_html() {
- http=http://validator.w3.org/check
- count=0
- total=`find -name '*.html'|wc -l`
- for file in `find -name '*.html'`; do
-
- count=$(( $count+1 ))
- echo -ne "\rChecking HTML file(s) ... $count/$total"
-
- full_uri=${uri}/${file/.\//}
- check="${http}?uri=${full_uri}&charset=${charset}&$doctype=${doctype}"
-
- w3c_valid "$check"
- echo -ne "\rChecking HTML file(s) ... "
- done
-
- echo -e "[\033[1;32m OK \033[0m]"
-}
-
-# CSS files
-check_css() {
- echo -n 'Checking CSS file(s) ... '
-
- http=http://jigsaw.w3.org/css-validator/validator
- check="${http}?uri=${uri}&profile=${profile}"
-
- w3c_valid "$check"
- echo -e "[\033[1;32m OK \033[0m]"
-}
-
-# RSS feed
-check_rss() {
- echo -n 'Checking RSS file(s) ... '
- http=http://feedvalidator.org/check.cgi
- check="${http}?url=${uri}/rss/feed.xml"
-
- rss_valid "$check"
- echo -e "[\033[1;32m OK \033[0m]"
-}
-
-case $1 in
- rss) check_rss ;;
- css) check_css ;;
- html) check_html ;;
- *) check_html
- check_css
- check_rss ;;
-esac
-
-exit 0
(DIR) diff --git a/validate.sh b/validate.sh
t@@ -0,0 +1,50 @@
+#!/bin/sh
+
+w3c() {
+ type=$1
+ file=$2
+
+ case $type in
+ html) curl -si \
+ -F "uploaded_file=@$file;text/html" \
+ -F uri-doctype=HTML5 \
+ https://validator.w3.org/check \
+ | grep -i ^x-w3c-validator-status:
+ ;;
+ css) curl -si \
+ -F "file=@$file" \
+ -F profile=css3 \
+ https://jigsaw.w3.org/css-validator/validator \
+ | grep -i ^x-w3c-validator-status:
+ ;;
+ rss) curl -si \
+ --data-urlencode "rawdata=$(< $file tr -d '\n\t')" \
+ --data "manual=1" \
+ https://validator.w3.org/feed/check.cgi \
+ | grep -o 'Valid RSS' \
+ ;;
+ esac | dos2unix | grep -o Valid | head -n1
+}
+
+case $1 in
+rss) pattern='*.xml' ;;
+css) pattern='*.css' ;;
+html) pattern='*.html' ;;
+*)
+ $0 rss
+ $0 css
+ $0 html
+ ;;
+esac
+
+# empty pattern won't match anything
+for file in $(find . -name "$pattern"); do
+ printf '[%4s] %s' "$1" "${file#./}"
+ val="$(w3c $1 $file)"
+ case $val in
+ Valid) printf "\r[ OK ]\n" ;;
+ *) printf "\r[FAIL]\n" ;;
+ esac
+done
+
+exit 0