#!/usr/bin/env bash set -euo pipefail repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" cd "${repo_root}" missing=0 while IFS= read -r -d '' file; do while IFS= read -r link; do target="${link#*](}" target="${target%)}" target="${target%%#*}" target="${target%% *}" target="${target#<}" target="${target%>}" case "${target}" in ''|\#|http://*|https://*|mailto:*) continue ;; esac resolved="$(dirname "${file}")/${target}" if [[ ! -e "${resolved}" ]]; then printf 'missing Markdown link: %s: %s -> %s\n' \ "${file}" "${target}" "${resolved}" >&2 missing=1 fi done < <(rg -o '\]\([^)]*\)' "${file}" || true) done < <( find . -type f \( -name '*.md' -o -name '*.markdown' \) \ -not -path './.git/*' \ -not -path './target/*' \ -print0 ) if [[ "${missing}" -ne 0 ]]; then exit 1 fi printf 'markdown local link check ok\n'