Files
Church-of-Kosmo/scripts/check_markdown_links.sh
Tomas Kracmar 9ee5acfa4f
Some checks failed
Docs Check / lint-and-links (push) Has been cancelled
Docs Check / translation-parity (push) Has been cancelled
Add docs governance and Czech parity updates
2026-03-26 17:12:39 +01:00

46 lines
1.0 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$repo_root"
missing_count=0
while IFS=$'\t' read -r src link; do
case "$link" in
''|'#'*|mailto:*|http://*|https://*)
continue
;;
esac
# Remove optional anchors and query strings for filesystem checks.
target="${link%%#*}"
target="${target%%\?*}"
[[ -z "$target" ]] && continue
if [[ "$target" == /* ]]; then
# Treat /path as repository-root relative for markdown in GitHub.
path="${repo_root}${target}"
else
path="$(dirname "$src")/$target"
fi
if [[ ! -e "$path" ]]; then
printf 'BROKEN: %s -> %s (missing: %s)\n' "$src" "$link" "$path"
missing_count=$((missing_count + 1))
fi
done < <(
while IFS= read -r file; do
perl -ne 'while(/\[[^\]]*\]\(([^)]+)\)/g){print "$ARGV\t$1\n"}' "$file"
done < <(rg --files -g '*.md')
)
if [[ "$missing_count" -gt 0 ]]; then
printf '\nFound %d broken markdown link(s).\n' "$missing_count"
exit 1
fi
echo "Markdown local links: OK"