Skip to content

Commit 58fbde1

Browse files
committed
Added check for orhphaned references
1 parent 5e4d055 commit 58fbde1

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

bin/check-refs.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
BOOK_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../book" && pwd)"
6+
cd "$BOOK_DIR"
7+
8+
echo "Checking for orphaned cross-references..."
9+
10+
# Extract all cross-references with filenames
11+
refs_with_files=$(grep -roh "<<[^>]*>>" *.adoc | sed 's/<<//g; s/>>//g')
12+
refs=$(echo "$refs_with_files" | sort -u)
13+
14+
# Extract all anchor definitions
15+
anchors=$(grep -roh "\[\[[^]]*\]\]" *.adoc | sed 's/\[\[//g; s/\]\]//g' | sort -u)
16+
17+
# Find orphaned references with their files
18+
orphaned=()
19+
while IFS= read -r ref; do
20+
if ! echo "$anchors" | grep -qx "$ref"; then
21+
# Find which files contain this orphaned reference
22+
files=$(grep -l "<<$ref>>" *.adoc | tr '\n' ' ')
23+
orphaned+=("$ref (in: $files)")
24+
fi
25+
done <<< "$refs"
26+
27+
if [ ${#orphaned[@]} -gt 0 ]; then
28+
echo "ERROR: Found ${#orphaned[@]} orphaned cross-reference(s):"
29+
printf ' - %s\n' "${orphaned[@]}"
30+
exit 1
31+
fi
32+
33+
echo "✓ No orphaned cross-references found"

bin/make-book.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#!/bin/bash
22

3+
set -e
4+
5+
# Check for orphaned cross-references
6+
./bin/check-refs.sh
7+
38
# create the target directory for where the book will build
49
rm -rf target
510
mkdir target

0 commit comments

Comments
 (0)