-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
$ cd uppy $ ./bin/check-broken-links.sh The broken links will be written to uppy/link_check_log.txt This script has been tested on Mac OS only.
- Loading branch information
1 parent
f8df085
commit 0047aed
Showing
2 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ yarn-error.log | |
.env | ||
tsconfig.tsbuildinfo | ||
tsconfig.build.tsbuildinfo | ||
link_check_log.txt | ||
|
||
dist/ | ||
lib/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/bin/bash | ||
|
||
# Log file to store the results | ||
LOGFILE="link_check_log.txt" | ||
|
||
# Clear the log file if it exists | ||
> $LOGFILE | ||
|
||
# Base directory where you want to scan (the parent of bin) | ||
BASE_DIR="$(cd "$(dirname "$0")/.." && pwd)" | ||
|
||
# Find all .md files in the project directory and subdirectories, excluding node_modules | ||
find "$BASE_DIR" -path "$BASE_DIR/node_modules" -prune -o -print | while read -r file; do | ||
echo "Scanning $file for broken links..." | ||
|
||
# Make the file path relative to BASE_DIR to remove the './bin/../' part | ||
real_file="${file#$BASE_DIR/}" | ||
|
||
# Use sed to extract URLs from Markdown format ([text](url)) | ||
# This matches URLs within parentheses after a closing square bracket | ||
sed -n 's/.*](\([^)]*\)).*/\1/p' "$file" | while IFS=: read -r url; do | ||
# Get the line number by searching for the URL | ||
line=$(grep -n "$url" "$file" | cut -d: -f1) | ||
|
||
# Check if URL is valid by getting the HTTP status code | ||
status_code=$(curl -o /dev/null --silent --head --write-out "%{http_code}" "$url") | ||
|
||
# Print and log only if status is 404 (error) | ||
if [ "$status_code" -eq 404 ]; then | ||
output="Broken link found: File: $real_file | Line: $line | URL: $url | Status: ERROR (404)" | ||
echo "$output" | tee -a $LOGFILE | ||
fi | ||
done | ||
done | ||
|
||
echo "Link check completed. Results saved in $LOGFILE." | tee -a $LOGFILE |