build-pdf.sh 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. bn | ja | ko | ml | ta | th | zh | zh_TW)
  36. echo "${languageId} is not supported to build a PDF"
  37. ;;
  38. en)
  39. pageDirs=("pages")
  40. ;;
  41. *)
  42. pageDirs=("pages.${languageId}")
  43. ;;
  44. esac
  45. fi
  46. for pageDir in "${pageDirs[@]}"; do
  47. process_page "../../${pageDir}"
  48. done
  49. }
  50. ###################################
  51. # MAIN
  52. ###################################
  53. main $1