diff --git a/tools/check-doc-links.sh b/tools/check-doc-links.sh new file mode 100755 index 00000000..e3238be4 --- /dev/null +++ b/tools/check-doc-links.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +# Check that all relative markdown links under docs/components resolve. +set -uo pipefail +cd "$(dirname "$0")/.." +for f in docs/components/*.md; do + [ -e "$f" ] || continue + # extract ](target) links, ignore http(s):, anchors, and mailto + grep -oE '\]\([^)]+\)' "$f" | sed -E 's/^\]\(//; s/\)$//' | while read -r link; do + case "$link" in + http://*|https://*|mailto:*|\#*) continue ;; + esac + target="${link%%#*}" # strip #anchor + [ -z "$target" ] && continue + resolved="$(cd "$(dirname "$f")" && cd "$(dirname "$target")" 2>/dev/null && pwd)/$(basename "$target")" + if [ ! -e "$resolved" ]; then + echo "BROKEN: $f -> $link" + fi + done +done +echo "link check done"