fix(tools): multiple configuration files will fail the test
This commit is contained in:
parent
d2fb98b3e5
commit
80cb0b3717
1 changed files with 27 additions and 4 deletions
|
@ -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" \
|
||||
|
|
Loading…
Reference in a new issue