From 80cb0b371754e96772a7907877a8ce196398ba3d Mon Sep 17 00:00:00 2001 From: Cotes Chung <11371340+cotes2020@users.noreply.github.com> Date: Thu, 6 Oct 2022 19:47:29 +0800 Subject: [PATCH] fix(tools): multiple configuration files will fail the test --- tools/test.sh | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/tools/test.sh b/tools/test.sh index 155df3e..a647bde 100755 --- a/tools/test.sh +++ b/tools/test.sh @@ -12,6 +12,8 @@ SITE_DIR="_site" _config="_config.yml" +_baseurl="" + help() { echo "Build and test the site content" echo @@ -24,18 +26,39 @@ help() { echo " -h, --help Print this information." } +read_baseurl() { + if [[ $_config == *","* ]]; then + # multiple config + IFS="," + read -ra config_array <<<"$_config" + + # reverse loop the config files + for ((i = ${#config_array[@]} - 1; i >= 0; i--)); do + _tmp_baseurl="$(grep '^baseurl:' "${config_array[i]}" | sed "s/.*: *//;s/['\"]//g;s/#.*//")" + + if [[ -n $_tmp_baseurl ]]; then + _baseurl="$_tmp_baseurl" + break + fi + done + + else + # single config + _baseurl="$(grep '^baseurl:' "$_config" | sed "s/.*: *//;s/['\"]//g;s/#.*//")" + fi +} + main() { # clean up if [[ -d $SITE_DIR ]]; then rm -rf "$SITE_DIR" fi - _baseurl="$(grep '^baseurl:' "$_config" | sed "s/.*: *//;s/['\"]//g;s/#.*//")" + read_baseurl # build - JEKYLL_ENV=production bundle exec jekyll build \ - --destination "$SITE_DIR$_baseurl" \ - --config "$_config" + JEKYLL_ENV=production bundle exec jekyll b \ + -d "$SITE_DIR$_baseurl" -c "$_config" # test bundle exec htmlproofer "$SITE_DIR" \