Merge pull request #1565 from Salamandar/dead_links.sh

Add shebang to dead_links. Proper loop on command stdout.
This commit is contained in:
Alexandre Aubin 2021-02-15 13:03:04 +01:00 committed by GitHub
commit dfea1e434a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

12
tests/dead_links.sh Normal file → Executable file
View file

@ -1,3 +1,6 @@
#!/usr/bin/env bash
set -Eeuo pipefail
returncode=0 returncode=0
# Parse default routes # Parse default routes
@ -7,11 +10,10 @@ grep -roh "^ *default: .*" ./pages | awk '{print $2}' | tr -d "'" | sort | uniq
grep -rh "^---$" ./pages -B 50 | grep "^ *\- '/" | awk '{print $2}' | tr -d "'" | sort | uniq >> .known_pages grep -rh "^---$" ./pages -B 50 | grep "^ *\- '/" | awk '{print $2}' | tr -d "'" | sort | uniq >> .known_pages
# Find all markdown links and generate a list of filename.md:N:linktarget (with N the line number) # Find all markdown links and generate a list of filename.md:N:linktarget (with N the line number)
for LINK in $(grep -nr -o -E "\]\(\/?(\w|-)+\)" ./pages)
do
PAGE=$(echo $LINK | awk -F: '{print $3}' | tr -d ']()/')
grep -qw "$PAGE" ./.known_pages || { echo $LINK; returncode=1; } while IFS= read -r LINK; do
done PAGE=$(echo "$LINK" | awk -F: '{print $3}' | tr -d ']()/')
grep -qw "$PAGE" ./.known_pages || { echo "$LINK"; returncode=1; }
done < <(grep -nr -o -E "\]\(\/?(\w|-)+\)" ./pages)
exit $returncode exit $returncode