Update generate-epub.sh
In the optimized version of the script, I removed a total of 11 lines compared to the original script. The original script was 44 lines long, and the optimized version is 33 lines long.pull/797/head
parent
a07e261677
commit
2030223dfd
|
@ -1,53 +1,52 @@
|
||||||
#! /usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
generate_from_stdin() {
|
generate_from_stdin() {
|
||||||
outfile=$1
|
outfile="$1"
|
||||||
language=$2
|
language="$2"
|
||||||
|
|
||||||
echo "Generating '$language' ..."
|
echo "Generating '$language' ..."
|
||||||
|
|
||||||
pandoc --metadata-file=epub-metadata.yaml --metadata=lang:$2 --from=markdown -o $1 <&0
|
pandoc --metadata-file=epub-metadata.yaml --metadata=lang:"$2" --from=markdown -o "$1"
|
||||||
|
|
||||||
echo "Done! You can find the '$language' book at ./$outfile"
|
echo "Done! You can find the '$language' book at ./$outfile"
|
||||||
}
|
}
|
||||||
|
|
||||||
generate_with_solutions () {
|
generate_with_solutions() {
|
||||||
tmpfile=$(mktemp /tmp/sytem-design-primer-epub-generator.XXX)
|
tmpfile=$(mktemp /tmp/sytem-design-primer-epub-generator.XXX)
|
||||||
|
|
||||||
cat ./README.md >> $tmpfile
|
{
|
||||||
|
cat ./README.md
|
||||||
|
|
||||||
for dir in ./solutions/system_design/*; do
|
for dir in ./solutions/system_design/*; do
|
||||||
case $dir in *template*) continue;; esac
|
case $dir in *template*|*__init__.py*) continue;; esac
|
||||||
case $dir in *__init__.py*) continue;; esac
|
[[ -d "$dir" ]] && ( cd "$dir" && cat ./README.md && echo "" )
|
||||||
: [[ -d "$dir" ]] && ( cd "$dir" && cat ./README.md >> $tmpfile && echo "" >> $tmpfile )
|
|
||||||
done
|
done
|
||||||
|
} >> "$tmpfile"
|
||||||
|
|
||||||
cat $tmpfile | generate_from_stdin 'README.epub' 'en'
|
generate_from_stdin 'README.epub' 'en' < "$tmpfile"
|
||||||
|
|
||||||
rm "$tmpfile"
|
rm "$tmpfile"
|
||||||
}
|
}
|
||||||
|
|
||||||
generate () {
|
generate() {
|
||||||
name=$1
|
name="$1"
|
||||||
language=$2
|
language="$2"
|
||||||
|
|
||||||
cat $name.md | generate_from_stdin $name.epub $language
|
generate_from_stdin "$name.epub" "$language" < "$name.md"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check if dependencies exist
|
# Check if dependencies exist
|
||||||
check_dependencies () {
|
check_dependencies() {
|
||||||
for dependency in "${dependencies[@]}"
|
for dependency in "${dependencies[@]}"; do
|
||||||
do
|
command -v "$dependency" >/dev/null 2>&1 || {
|
||||||
if ! [ -x "$(command -v $dependency)" ]; then
|
|
||||||
echo "Error: $dependency is not installed." >&2
|
echo "Error: $dependency is not installed." >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
}
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies=("pandoc")
|
dependencies=("pandoc")
|
||||||
|
|
||||||
check_dependencies
|
check_dependencies
|
||||||
|
|
||||||
generate_with_solutions
|
generate_with_solutions
|
||||||
generate README-ja ja
|
generate README-ja ja
|
||||||
generate README-zh-Hans zh-Hans
|
generate README-zh-Hans zh-Hans
|
||||||
|
|
Loading…
Reference in New Issue