-
Notifications
You must be signed in to change notification settings - Fork 2
/
build-index
executable file
·54 lines (46 loc) · 1.43 KB
/
build-index
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
#!/bin/bash
root=$(git rev-parse --show-toplevel)
function collect_challenges_by_category {
local dir=$1
local level=$2
while read -r subdir; do
if [[ -f "$subdir/Package.swift" ]]; then
name=$(basename "$subdir" | "$root/prettify")
echo "- [$name](${subdir/$root\//})"
continue
fi
echo "$(yes '#' | head -n $level | tr -d '\n') $(basename "$subdir")"
echo
collect_challenges_by_category "$subdir" $((level + 1))
echo
done < <(find "$dir" -mindepth 1 -maxdepth 1 -type d -not -name "*.*" | sort)
}
function collect_challenges_by_difficulty {
local dir=$1
local difficulty=$2
local lines=
while read -r package; do
subdir=$(dirname "$package")
readme=$subdir/README.md
if grep -q "Difficulty: $difficulty" "$readme"; then
name=$(basename "$subdir" | "$root/prettify")
lines=$lines"\n- [$name](${subdir/$root\//})"
fi
done < <(find "$dir" -name "Package.swift")
echo -e "${lines:-\nNone yet}" | sort
}
echo "Challenges by Category"
echo "----------------------"
echo
collect_challenges_by_category "$root" 3
echo "Challenges by Difficulty"
echo "------------------------"
echo
echo "### Easy"
collect_challenges_by_difficulty "$root" "easy"
echo
echo "### Medium"
collect_challenges_by_difficulty "$root" "medium"
echo
echo "### Hard"
collect_challenges_by_difficulty "$root" "hard"