forked from hanabi/hanabi.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
move-levels.sh
executable file
·52 lines (45 loc) · 1.7 KB
/
move-levels.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
#!/bin/bash
set -euo pipefail # Exit on errors and undefined variables.
function usage() {
echo "Usage: ./move-levels.sh A"
echo "Moves levels A, A+1, ..., to A+1, A+2, ..."
exit 64
}
if [ $# -ne 1 ]; then
usage
fi
if ! [[ $1 =~ ^[0-9]+$ ]]; then
usage
fi
MAX_LEVEL="$(find docs/ -maxdepth 1 -name 'level-*.mdx' | wc --lines)"
echo "Setting old MAX_LEVEL to $MAX_LEVEL"
readarray -t MDX_FILES < <(git ls-files 'docs/*.mdx')
for x in $(seq "$MAX_LEVEL" -1 "$1"); do
((y = x + 1))
sed -i "s/Level $x\\b/Level $y/g" "${MDX_FILES[@]}"
sed -i "s/level $x\\b/level $y/g" "${MDX_FILES[@]}"
sed -i "s/level-$x\\b/level-$y/g" "${MDX_FILES[@]}"
sed -i "s/\\[$x\\]/\\[$y\\]/g" docs/learning-path.mdx
done
git diff --stat
for x in $(seq "$MAX_LEVEL" -1 "$1"); do
((y = x + 1))
if [ -d "image-generator/yml/level-$x" ]; then
git mv "image-generator/yml/level-$x" "image-generator/yml/level-$y"
fi
if [ -d "image-generator/yml/challenge-questions/level-$x" ]; then
git mv "image-generator/yml/challenge-questions/level-$x" "image-generator/yml/challenge-questions/level-$y"
fi
if [ -f "docs/challenge-questions/level-$x.mdx" ]; then
git mv "docs/challenge-questions/level-$x.mdx" "docs/challenge-questions/level-$y.mdx"
fi
if [ -f "docs/level-$x.mdx" ]; then
git mv "docs/level-$x.mdx" "docs/level-$y.mdx"
fi
done
echo "+----------------------------------------------------------+"
echo "| == REMINDERS == |"
echo "| Adjust sidebars.js and MAX_LEVEL in static/js/hotkey.js |"
echo "| and verify he table at the end of docs/learning-path.mdx |"
echo "| You should also create the file docs/level-$1.mdx |"
echo "+----------------------------------------------------------+"