diff --git a/build-site.sh b/build-site.sh deleted file mode 100755 index 2ee9027..0000000 --- a/build-site.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash - -COMPOSE_FILE="compose-build-site.yaml" - -docker compose -f "$COMPOSE_FILE" up -docker compose -f "$COMPOSE_FILE" down diff --git a/compose-build-site.yaml b/compose-build-site.yaml index 502022c..e8e8684 100644 --- a/compose-build-site.yaml +++ b/compose-build-site.yaml @@ -7,4 +7,4 @@ services: working_dir: ${CONTAINER_WORK_DIR} volumes: - ${VOLUME_SOURCE}:${VOLUME_TARGET} - command: bundle exec jekyll build + command: bundle exec jekyll build ${JEKYLL_CMD_EXTRA_OPTIONS} diff --git a/compose.yaml b/compose.yaml index 04656f8..2cf8bc3 100644 --- a/compose.yaml +++ b/compose.yaml @@ -9,4 +9,4 @@ services: working_dir: ${CONTAINER_WORK_DIR} volumes: - ${VOLUME_SOURCE}:${VOLUME_TARGET} - command: bundle exec jekyll serve -H 0.0.0.0 -P ${CONTAINER_PORT} + command: bundle exec jekyll serve -H 0.0.0.0 -P ${CONTAINER_PORT} ${JEKYLL_CMD_EXTRA_OPTIONS} diff --git a/start.sh b/start.sh new file mode 100755 index 0000000..ed2e871 --- /dev/null +++ b/start.sh @@ -0,0 +1,41 @@ +#!/bin/bash + +set -e + +nc='\033[0m' +r='\033[0;31m' +g='\033[0;32m' + +LANGS=( + "en" + "cn" +) + +while [[ "$1" =~ ^"-" ]]; do + if [ "$1" = "-l" ]; then + shift 1; lang=$1 + fi + shift 1 +done + +[ -z "$1" ] && action="serve" || action=$1 + +if [ -z "$lang" ]; then + lang="en" +elif [[ ! ${LANGS[*]} =~ $lang ]]; then + echo -e "\n ERROR: Undefined lang: ${r}$lang${nc}\n" && exit 1 +fi +echo -e "\n ACTION: ${g}$action${nc}, LANG: ${g}$lang${nc}\n" + +# Provide extra options for jekyll when needed. +[ "$lang" != "en" ] && jekyll_cmd_extra_options="--config _config.yml,$lang/_config.yml" + +# Docker compose +if [ "$action" == "build" ]; then + COMPOSE_FILE="compose-build-site.yaml" + + docker compose -f "$COMPOSE_FILE" up + docker compose -f "$COMPOSE_FILE" down +else + JEKYLL_CMD_EXTRA_OPTIONS="$jekyll_cmd_extra_options" docker compose up +fi