The code, templates and content for my Hakyll powered blog at blog.rekahsoft.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

110 lines
2.8KB

  1. #!/bin/bash
  2. function run_site_only() {
  3. [ "$SITE_ONLY" == "true" ]
  4. }
  5. function run_override_only() {
  6. [ "$OVERRIDE_ONLY" == "true" ]
  7. }
  8. case "$1" in
  9. -)
  10. OVERRIDE_ONLY=true
  11. shift
  12. ;;
  13. --)
  14. SITE_ONLY=true
  15. shift
  16. ;;
  17. esac
  18. case "$1" in
  19. test)
  20. if [[ "$2" == "-s" || "$2" == "--run-selenium" ]]; then
  21. if ! type selenium &> /dev/null; then
  22. echo "Failed to run Selenium. It must not be installed or not accessible on \$PATH!"
  23. exit 1
  24. fi
  25. echo "Running Selenium..."
  26. selenium 2> /dev/null &
  27. sleep 3s
  28. fi
  29. # Test site
  30. stack test
  31. ;;
  32. gencss)
  33. shift
  34. stack exec gencss -- "$@"
  35. ;;
  36. # Override of hakyll site commands
  37. -h|--help)
  38. run_override_only || ! run_site_only && cat << EOF
  39. Wraps hakyll's provided site tool to augment certain commands.
  40. Usage:
  41. ./site [-|--] COMMAND
  42. Available commands:
  43. build*
  44. clean*
  45. deploy*
  46. gencss
  47. test
  48. Hakyll site commands:
  49. build
  50. check
  51. clean
  52. deploy
  53. preview
  54. rebuild
  55. server
  56. watch
  57. Starred (*) commands indicate a overridden hakyll site command. However once the override is
  58. run, the corresponding hakyll command is then run. This can be disabled with by specifying '--'
  59. as the first argument, which will then pass all remaining arguments to the hakyll site command.
  60. Similarily, to only run the override, specify '-' as the first argument.
  61. For more details about hakyll site commands and options, see './site -- --help'.
  62. EOF
  63. # Only run hakyll site --help command if override was not run
  64. run_override_only && exit
  65. # Only run hakyll site --help command if -- site only
  66. run_site_only && stack exec blog-rekahsoft-ca -- --help | sed 's/\(Usage: \)blog-rekahsoft-ca/\1.\/site -/g'
  67. ;;
  68. build)
  69. run_override_only || ! run_site_only && stack build
  70. run_override_only && exit $?
  71. ;;&
  72. clean)
  73. run_override_only || ! run_site_only && stack clean
  74. run_override_only && exit $?
  75. ;;&
  76. deploy)
  77. pushd infra > /dev/null
  78. # Only run hakyll site deploy command when site-only is given. Additionally, when
  79. # neither site-only or override-only are given, run only the override. The deploy
  80. # override uses terraform which is also setup to deploy the hakyll site static files
  81. run_override_only || ! run_site_only && (
  82. export PLAN=".plans/local-$(date +%F_%R).plan"
  83. [ ! -d .plans ] && mkdir .plans
  84. make plan deploy
  85. ) && exit $?
  86. run_site_only && export S3_BUCKET="$(terraform output s3_bucket_static)"
  87. popd > /dev/null
  88. ;;&
  89. *)
  90. stack exec blog-rekahsoft-ca -- "$@"
  91. ;;
  92. esac