build-pdf.sh 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/usr/bin/env bash
  2. # SPDX-License-Identifier: MIT
  3. # This script is executed by GitHub Actions when a PR is merged (i.e. in the `Build PDF` step).
  4. set -ex
  5. function process_page {
  6. pageDir="$1"
  7. folder=$(basename "${pageDir}")
  8. case $folder in
  9. pages.bn | pages.ja | pages.ko | pages.ml | pages.ta | pages.th | pages.zh | pages.zh_TW)
  10. ;;
  11. pages)
  12. python3 render.py "${pageDir}" -c solarized-light
  13. ;;
  14. *)
  15. language="${folder##*.}"
  16. python3 render.py "${pageDir}" -c basic -o "tldr-book-${language}.pdf"
  17. ;;
  18. esac
  19. }
  20. function main {
  21. languageId="$1"
  22. if [ -z "$languageId" ]; then
  23. changedFiles=$(git diff-tree --no-commit-id --name-only -r "$(git rev-parse HEAD)")
  24. changedPageDirs=$(echo "$changedFiles" | awk -F/ '/^(pages[^\/]+|pages)\//{print $1}' | sort -u)
  25. if [ -z "$changedPageDirs" ]; then
  26. pageDirs=()
  27. else
  28. mapfile -t pageDirs <<< "$changedPageDirs"
  29. fi
  30. else
  31. case $languageId in
  32. "all")
  33. pageDirs=(../../pages*)
  34. ;;
  35. *)
  36. pageDirs=("pages.${languageId}")
  37. esac
  38. fi
  39. for pageDir in "${pageDirs[@]}"; do
  40. process_page "../../${pageDir}"
  41. done
  42. }
  43. ###################################
  44. # MAIN
  45. ###################################
  46. main $1