build-pdf: only build changed folders since last commit (#11773)

* build-pdf: only build changed folders since last commit

* build-pdf: only determine language if needed

* build-pdf: refactor the script
pull/23/head
Sebastiaan Speck 2023-12-19 13:08:20 +01:00 committed by GitHub
parent 93bf18f39a
commit 1de7b5a80b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 21 additions and 4 deletions

25
scripts/pdf/build-pdf.sh Normal file → Executable file
View File

@ -7,7 +7,6 @@ set -ex
function process_page {
pageDir="$1"
folder=$(basename "${pageDir}")
language="${folder##*.}"
case $folder in
pages.bn | pages.ja | pages.ko | pages.ml | pages.ta | pages.th | pages.zh | pages.zh_TW)
;;
@ -15,14 +14,32 @@ function process_page {
python3 render.py "${pageDir}" -c solarized-light
;;
*)
language="${folder##*.}"
python3 render.py "${pageDir}" -c basic -o "tldr-book-${language}.pdf"
;;
esac
}
function main {
for pageDir in ../../pages*; do
process_page "${pageDir}"
type="$1"
case $type in
"all")
pageDirs=(../../pages*)
;;
*)
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
;;
esac
for pageDir in "${pageDirs[@]}"; do
process_page "../../${pageDir}"
done
}
@ -30,4 +47,4 @@ function main {
# MAIN
###################################
main
main $1