Skip to content

Commit

Permalink
fix(tools): multiple configuration files will fail the test
Browse files Browse the repository at this point in the history
  • Loading branch information
cotes2020 committed Oct 6, 2022
1 parent d2fb98b commit 80cb0b3
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions tools/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ SITE_DIR="_site"

_config="_config.yml"

_baseurl=""

help() {
echo "Build and test the site content"
echo
Expand All @@ -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" \
Expand Down

0 comments on commit 80cb0b3

Please sign in to comment.