diff options
author | Michał Łyszczek <michal.lyszczek@bofc.pl> | 2018-01-21 16:51:22 +0100 |
---|---|---|
committer | Michał Łyszczek <michal.lyszczek@bofc.pl> | 2018-01-21 16:51:22 +0100 |
commit | e0fe073e20a7b1ec76a11af391222c01462d5c6a (patch) | |
tree | f5d20e9b358925dd2fb0ebad5de60fbb65391733 | |
parent | 3c48d7036d6ebe6bf7e3086d2a2f6c61cd72285c (diff) | |
download | kursg-find-index-recursive.tar.gz kursg-find-index-recursive.tar.bz2 kursg-find-index-recursive.zip |
add: very simple relative link checker in generated sitesfind-index-recursive
-rwxr-xr-x | link-checker.sh | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/link-checker.sh b/link-checker.sh new file mode 100755 index 0000000..241ebfd --- /dev/null +++ b/link-checker.sh @@ -0,0 +1,38 @@ +#!/bin/sh + +if [ $# -ne 1 ] +then + echo "usage: ${0} <path>" + exit 1 +fi + +cd "${1}" +find . -name "*.html" -print0 | while IFS= read -r -d $'\0' f +do + error=0 + echo -n "${f} ..." + links="$(grep -Po '(?<=href=")[^"]*' "${f}")" + cd "$(dirname ${f})" + + while read -r line + do + if [ "${line}" = "/" ] || [ "${line:0:4}" = "http" ] + then + continue + fi + + if [ ! -f "${line}" ] + then + error=1 + echo " error: ${line}" + continue + fi + done <<< "${links}" + + if [ "${error}" = "0" ] + then + echo "[ok]" + fi + + cd - > /dev/null +done |