From f1c6d2a817425973ed4121f942bcbd460a619f86 Mon Sep 17 00:00:00 2001 From: Cotes Chung <11371340+cotes2020@users.noreply.github.com> Date: Thu, 2 May 2024 03:18:35 +0800 Subject: [PATCH] build: enhance the run script --- tools/run | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/tools/run b/tools/run index 8072e41..04f23f5 100755 --- a/tools/run +++ b/tools/run @@ -2,4 +2,49 @@ # # Run jekyll serve and then launch the site -bundle exec jekyll s -H 0.0.0.0 -l +prod=false +command="bundle exec jekyll s -l" +host="127.0.0.1" + +help() { + echo "Usage:" + echo + echo " bash /path/to/run [options]" + echo + echo "Options:" + echo " -H, --host [HOST] Host to bind to." + echo " -p, --production Run Jekyll in 'production' mode." + echo " -h, --help Print this help information." +} + +while (($#)); do + opt="$1" + case $opt in + -H | --host) + host="$2" + shift 2 + ;; + -p | --production) + prod=true + shift + ;; + -h | --help) + help + exit 0 + ;; + *) + echo -e "> Unknown option: '$opt'\n" + help + exit 1 + ;; + esac +done + +command="$command -H $host" + +if $prod; then + command="JEKYLL_ENV=production $command" +fi + +echo -e "\n> $command\n" +eval "$command"