forked from dylanaraps/pure-bash-bible
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
路24 lines (20 loc) 路 738 Bytes
/
build.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
#!/usr/bin/env bash
#
# Turn the single document bible into a book separated by chapters.
main() {
rm -rf manuscript
mkdir -p manuscript
# Split the README.md into chapters based on markers.
while IFS=$'\n' read -r line; do
[[ "$chap" ]] && chapter[$i]+="$line"$'\n'
[[ "$line" == "<!-- CHAPTER START -->" ]] && chap=1
[[ "$line" == "<!-- CHAPTER END -->" ]] && { chap=; ((i++)); }
done < README.md
# Write the chapters to separate files.
for i in "${!chapter[@]}"; do
: "${chapter[$i]/$'\n'*}"; : "${_/\# }"; : "${_,,}"
printf '%s\n' "${chapter[$i]}" > "manuscript/chapter${i}.txt"
printf '%s\n' "chapter${i}.txt" >> "manuscript/Book.txt"
done
}
main