Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions scripts/check-links.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be #!/bin/sh?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jorgeorpinel Can you try and let me know?

# 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 <base-url> [<list-of-md-files>]
#
# If <base-url> 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/*/*.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'

shopt -s globstar
for file in $files; do
grep -o ']([^)]*)' $file | sed -e 's/^](//' -e 's/)$//' | \
while read link; do
case $link in
/*) url="${BASE_URL}${link}" ;;
'#'*) continue ;;
'') continue ;;
*) url=$link ;;
esac
wget $settings "$url" || echo "$file: '$link'"
done
done