Skip to content

Commit

Permalink
Rename build-site.sh to start.sh to handle build and serve
Browse files Browse the repository at this point in the history
  • Loading branch information
Kjuly committed May 10, 2024
1 parent fe0935e commit ebfe361
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 8 deletions.
6 changes: 0 additions & 6 deletions build-site.sh

This file was deleted.

2 changes: 1 addition & 1 deletion compose-build-site.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
2 changes: 1 addition & 1 deletion compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
41 changes: 41 additions & 0 deletions start.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit ebfe361

Please sign in to comment.