2023-08-18 19:10:43 +03:00
|
|
|
#!/usr/bin/env bash
|
2019-05-12 13:21:14 +03:00
|
|
|
|
|
|
|
generate_from_stdin() {
|
2023-08-18 19:10:43 +03:00
|
|
|
outfile="$1"
|
|
|
|
language="$2"
|
|
|
|
|
2019-05-12 13:21:14 +03:00
|
|
|
echo "Generating '$language' ..."
|
2023-08-18 19:10:43 +03:00
|
|
|
|
|
|
|
pandoc --metadata-file=epub-metadata.yaml --metadata=lang:"$2" --from=markdown -o "$1"
|
|
|
|
|
2019-05-12 13:21:14 +03:00
|
|
|
echo "Done! You can find the '$language' book at ./$outfile"
|
|
|
|
}
|
|
|
|
|
2023-08-18 19:10:43 +03:00
|
|
|
generate_with_solutions() {
|
2019-05-12 13:21:14 +03:00
|
|
|
tmpfile=$(mktemp /tmp/sytem-design-primer-epub-generator.XXX)
|
2023-08-18 19:10:43 +03:00
|
|
|
|
|
|
|
{
|
|
|
|
cat ./README.md
|
|
|
|
|
|
|
|
for dir in ./solutions/system_design/*; do
|
|
|
|
case $dir in *template*|*__init__.py*) continue;; esac
|
|
|
|
[[ -d "$dir" ]] && ( cd "$dir" && cat ./README.md && echo "" )
|
|
|
|
done
|
|
|
|
} >> "$tmpfile"
|
|
|
|
|
|
|
|
generate_from_stdin 'README.epub' 'en' < "$tmpfile"
|
2019-05-12 13:21:14 +03:00
|
|
|
rm "$tmpfile"
|
|
|
|
}
|
|
|
|
|
2023-08-18 19:10:43 +03:00
|
|
|
generate() {
|
|
|
|
name="$1"
|
|
|
|
language="$2"
|
|
|
|
|
|
|
|
generate_from_stdin "$name.epub" "$language" < "$name.md"
|
2019-05-12 13:21:14 +03:00
|
|
|
}
|
|
|
|
|
2022-04-23 16:14:45 +03:00
|
|
|
# Check if dependencies exist
|
2023-08-18 19:10:43 +03:00
|
|
|
check_dependencies() {
|
|
|
|
for dependency in "${dependencies[@]}"; do
|
|
|
|
command -v "$dependency" >/dev/null 2>&1 || {
|
2020-07-04 04:24:24 +03:00
|
|
|
echo "Error: $dependency is not installed." >&2
|
|
|
|
exit 1
|
2023-08-18 19:10:43 +03:00
|
|
|
}
|
2020-07-04 04:24:24 +03:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
dependencies=("pandoc")
|
|
|
|
check_dependencies
|
2023-08-18 19:10:43 +03:00
|
|
|
|
2019-05-12 13:21:14 +03:00
|
|
|
generate_with_solutions
|
|
|
|
generate README-ja ja
|
|
|
|
generate README-zh-Hans zh-Hans
|
|
|
|
generate README-zh-TW zh-TW
|