Created
January 19, 2021 09:37
-
-
Save stfwn/ddeb79a912b701d657b08783c16fdc41 to your computer and use it in GitHub Desktop.
Find dead links in your ReStructuredText files
This file contains hidden or 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
#!/bin/bash | |
# This script grabs ReStructuredText-style hyperlinks in all rst files from cwd down, | |
# then prints a list of status codes for a GET request to each of them. It's useful | |
# for finding dead links. | |
# This will match: | |
# - "<www.example.com>" | |
# - "<https://www.example.com" | |
# - "<https://example.com" | |
# | |
# This will not match: | |
# - "<example.com>" | |
# - "www.example.com" | |
# - "https://example.com" | |
echo "Response Code URL" | |
grep --extended-regexp\ | |
--recursive\ | |
--only-matching\ | |
--no-filename\ | |
--include="*.rst"\ | |
"<((https://)|(www)).*>"\ | |
| sed "s/[<>]//g"\ | |
| xargs -n 1 curl -sL -o /dev/null -w '%{response_code}\t\t%{url_effective}\n' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment