File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed
Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+
3+ set -euf -o pipefail
4+
5+
6+ function usage {
7+ cat << EOF
8+ Find all canonicalURL front matter values in all Markdown files from a directory and verify they return an OK status code.
9+
10+ Usage:
11+ $0 <PATH>
12+
13+ Examples:
14+ $0 src/data/markdown
15+ EOF
16+ }
17+
18+
19+ if [[ $# -ne 1 ]]; then
20+ usage
21+ exit 1
22+ fi
23+
24+ errors=0
25+ find " $1 " -type f -name ' *.md' -exec grep -H ' ^canonicalUrl: ' {} \; | while IFS= read -r line; do
26+ file=" $( echo " ${line} " | cut -d: -f1) "
27+ url=" $( echo " ${line} " | cut -d: -f2- | cut -d' ' -f2) "
28+ status=" $( curl -X HEAD -s -o /dev/null -w ' %{http_code}' " ${url} " ) "
29+
30+ if [[ " ${status} " -ne 200 ]]; then
31+ echo " ERROR: ${file} : ${url} returned status ${status} "
32+ errors=$(( errors + 1 ))
33+ else
34+ echo " OK: ${file} : ${url} returned status ${status} " >&2
35+ fi
36+
37+ sleep 0.1
38+ done
You can’t perform that action at this time.
0 commit comments