2023-10-21 22:04:22 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
# SPDX-License-Identifier: MIT
|
|
|
|
|
|
|
|
# This script is executed by GitHub Actions when a PR is merged (i.e. in the `Build PDF` step).
|
|
|
|
set -ex
|
|
|
|
|
|
|
|
function process_page {
|
|
|
|
pageDir="$1"
|
|
|
|
folder=$(basename "${pageDir}")
|
|
|
|
case $folder in
|
|
|
|
pages.bn | pages.ja | pages.ko | pages.ml | pages.ta | pages.th | pages.zh | pages.zh_TW)
|
|
|
|
;;
|
|
|
|
pages)
|
|
|
|
python3 render.py "${pageDir}" -c solarized-light
|
|
|
|
;;
|
|
|
|
*)
|
2023-12-17 18:18:04 +00:00
|
|
|
language="${folder##*.}"
|
2023-10-21 22:04:22 +01:00
|
|
|
python3 render.py "${pageDir}" -c basic -o "tldr-book-${language}.pdf"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
function main {
|
2023-12-19 16:37:18 +00:00
|
|
|
languageId="$1"
|
|
|
|
if [ -z "$languageId" ]; then
|
|
|
|
changedFiles=$(git diff-tree --no-commit-id --name-only -r "$(git rev-parse HEAD)")
|
|
|
|
changedPageDirs=$(echo "$changedFiles" | awk -F/ '/^(pages[^\/]+|pages)\//{print $1}' | sort -u)
|
|
|
|
if [ -z "$changedPageDirs" ]; then
|
|
|
|
pageDirs=()
|
|
|
|
else
|
|
|
|
mapfile -t pageDirs <<< "$changedPageDirs"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
case $languageId in
|
2023-12-19 16:44:56 +00:00
|
|
|
all)
|
2023-12-19 16:37:18 +00:00
|
|
|
pageDirs=(../../pages*)
|
|
|
|
;;
|
2023-12-19 16:44:56 +00:00
|
|
|
bn | ja | ko | ml | ta | th | zh | zh_TW)
|
|
|
|
echo "${languageId} is not supported to build a PDF"
|
|
|
|
;;
|
|
|
|
en)
|
|
|
|
pageDirs=("pages")
|
|
|
|
;;
|
2023-12-19 16:37:18 +00:00
|
|
|
*)
|
|
|
|
pageDirs=("pages.${languageId}")
|
2023-12-19 16:44:56 +00:00
|
|
|
;;
|
2023-12-19 16:37:18 +00:00
|
|
|
esac
|
|
|
|
fi
|
2023-12-17 18:58:16 +00:00
|
|
|
|
|
|
|
for pageDir in "${pageDirs[@]}"; do
|
|
|
|
process_page "../../${pageDir}"
|
|
|
|
done
|
2023-10-21 22:04:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
###################################
|
|
|
|
# MAIN
|
|
|
|
###################################
|
|
|
|
|
2023-12-17 14:18:19 +00:00
|
|
|
main $1
|