bin/verify-links
#!/usr/bin/env bash
# Enable strict error handling
set -euo pipefail
# Logger function
log_info() {
echo -e "\e[32m✅ $1\e[0m"
}
log_warn() {
echo -e "\e[33m👀 $1\e[0m"
}
log_error() {
echo -e "\e[31m❌ $1\e[0m" >&2
}
matches=$(
{
# Output README.md
cat README.md
# Find comments in the lib directory
grep -EhoR '# .*' lib
} |
# Extract URLs from the combined output
grep -Eo 'https?://[^ )>,"]+' |
uniq
)
failed=false
# Check each URL
while IFS= read -r url; do
{
response=$(curl -s -o /dev/null -w "%{http_code}" "$url")
case $response in
200)
log_info "$response $url"
;;
301|302)
log_warn "$response $url"
;;
*)
failed=true
log_error "$response $url"
;;
esac
} &
done <<< "$matches"
# Wait for all background jobs to finish
wait
if $failed; then
log_warn "Please fix broken documentation links."
exit 1
fi