forked from precice/tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck.sh
executable file
·74 lines (64 loc) · 2.07 KB
/
check.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/bash
# Run this script at the root of the repository to check images and permalinks
CODE=0
# Check tutorials
IGNORE="tools|quickstart"
tutorials=$(find . -maxdepth 1 -type d -not -name ".*" | grep -vE $IGNORE | sed "s/^.\///")
for tutorial in $tutorials; do
# Check permalinks
docs=$(find "./$tutorial" -maxdepth 1 -type f -name "*.md" -print0 | xargs -0 grep -l "permalink:" | sed "s/^.\///")
for doc in $docs; do
link=$(grep "permalink:" "$doc" | sed "s/permalink: \+//")
prefix="tutorials-$tutorial"
if ! [[ $link =~ ^$prefix ]]; then
echo "$doc: error: wrong permalink"
echo "$doc: note: permalink \"$link\" does not start with \"$prefix\""
CODE=1
else
echo "$doc: info: correct permalink"
echo "$doc: note: permalink is \"$link\""
fi
echo
done
images=$(find "./$tutorial/images" -type f 2> /dev/null | sed "s/^.\///")
prefix="tutorials-$tutorial-"
for img in $images; do
if ! [[ $img =~ ^$tutorial/images/$prefix ]]; then
echo "$img: error: wrong filename"
echo "$img: note: expected prefix \"$prefix\""
CODE=1
else
echo "$img: info: correct filename"
fi
echo
done
done
# Check quickstart
docs=$(find ./quickstart -maxdepth 1 -type f -name "*.md" -print0 | xargs -0 grep -l "permalink:" | sed "s/^.\///")
for doc in $docs; do
link=$(grep "permalink:" "$doc" | sed "s/permalink: \+//")
prefix="quickstart"
if ! [[ $link =~ ^$prefix ]]; then
echo "$doc: error: wrong permalink"
echo "$doc: note: permalink \"$link\" does not start with \"$prefix\""
CODE=1
else
echo "$doc: info: correct permalink"
echo "$doc: note: permalink is \"$link\""
fi
echo
done
images=$(find ./quickstart/images -type f 2> /dev/null | sed "s/^.\///")
prefix="quickstart-"
for img in $images; do
if ! [[ $img =~ ^quickstart/images/$prefix ]]; then
echo "$img: error: wrong filename"
echo "$img: note: expected prefix \"$prefix\""
CODE=1
else
echo "$img: info: correct filename"
fi
echo
done
[ ! "$CODE" -eq "0" ] && echo "There have been errors"
exit $CODE