From ed1e7770d73330e109dc309b3a07f694c80b8809 Mon Sep 17 00:00:00 2001 From: Dashamir Hoxha Date: Thu, 10 Oct 2019 15:36:30 +0200 Subject: [PATCH 1/3] Script to check links on .md files --- scripts/check-links.sh | 45 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100755 scripts/check-links.sh diff --git a/scripts/check-links.sh b/scripts/check-links.sh new file mode 100755 index 0000000000..a4447d1464 --- /dev/null +++ b/scripts/check-links.sh @@ -0,0 +1,45 @@ +#!/bin/bash +# Check links on the given .md files. If no files are given, check all +# the .md files of the project. +# Usage: +# scripts/check_links.sh [] +# +# If is missing, default is 'https://dvc.org' +# If the list of files is missing, all the .md files is 'static/' will be checked +# +# Examples: +# scripts/check_links.sh https://dvc.org static/docs/user-guide/*.md +# scripts/check_links.sh http://localhost:3000 +# scripts/check_links.sh + +cd $(dirname $0) +cd .. + +# wget settings +# the option '--max-redirect=0' disables redirections +settings="-q --max-redirect=0 --method=HEAD" + +BASE_URL=${1:-https://dvc.org} +BASE_URL=${BASE_URL%/} # remove a trailing / +shift + +files="$@" +[[ -z $files ]] && files='static/**/*.md' +#echo "$files" # debug + +shopt -s globstar +for file in $files; do + #echo "===== $file" # debug + grep -o ']([^)]*)' $file | sed -e 's/^](//' -e 's/)$//' | \ + while read link; do + case $link in + /*) url="${BASE_URL}${link}" ;; + '#'*) continue ;; + '') continue ;; + *) url=$link ;; + esac + #echo "--- $url" # debug + wget $settings "$url" || echo "$file: '$link'" + done +done + From 93d42c8cc3dd5d7d977a70185f4b67b657110e7f Mon Sep 17 00:00:00 2001 From: Dashamir Hoxha Date: Thu, 10 Oct 2019 16:20:44 +0200 Subject: [PATCH 2/3] Small fix --- scripts/check-links.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/check-links.sh b/scripts/check-links.sh index a4447d1464..61f571f026 100755 --- a/scripts/check-links.sh +++ b/scripts/check-links.sh @@ -5,7 +5,7 @@ # scripts/check_links.sh [] # # If is missing, default is 'https://dvc.org' -# If the list of files is missing, all the .md files is 'static/' will be checked +# If the list of files is missing, all the .md files in 'static/' will be checked # # Examples: # scripts/check_links.sh https://dvc.org static/docs/user-guide/*.md @@ -42,4 +42,3 @@ for file in $files; do wget $settings "$url" || echo "$file: '$link'" done done - From 93f389e8385efbdbe37d0baab6f60dd7f5a80de9 Mon Sep 17 00:00:00 2001 From: Dashamir Hoxha Date: Sat, 12 Oct 2019 22:30:39 +0200 Subject: [PATCH 3/3] Remove debug code etc. --- scripts/check-links.sh | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/scripts/check-links.sh b/scripts/check-links.sh index 61f571f026..12d72de243 100755 --- a/scripts/check-links.sh +++ b/scripts/check-links.sh @@ -4,11 +4,11 @@ # Usage: # scripts/check_links.sh [] # -# If is missing, default is 'https://dvc.org' -# If the list of files is missing, all the .md files in 'static/' will be checked +# If is missing, default is 'https://dvc.org'. If the list +# of files is missing, all the .md files in 'static/' will be checked # # Examples: -# scripts/check_links.sh https://dvc.org static/docs/user-guide/*.md +# scripts/check_links.sh https://dvc.org static/docs/*/*.md # scripts/check_links.sh http://localhost:3000 # scripts/check_links.sh @@ -25,11 +25,9 @@ shift files="$@" [[ -z $files ]] && files='static/**/*.md' -#echo "$files" # debug shopt -s globstar for file in $files; do - #echo "===== $file" # debug grep -o ']([^)]*)' $file | sed -e 's/^](//' -e 's/)$//' | \ while read link; do case $link in @@ -38,7 +36,6 @@ for file in $files; do '') continue ;; *) url=$link ;; esac - #echo "--- $url" # debug wget $settings "$url" || echo "$file: '$link'" done done