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"
|
_config="_config.yml"
|
||||||
|
|
||||||
|
_baseurl=""
|
||||||
|
|
||||||
help() {
|
help() {
|
||||||
echo "Build and test the site content"
|
echo "Build and test the site content"
|
||||||
echo
|
echo
|
||||||
|
@ -24,18 +26,39 @@ help() {
|
||||||
echo " -h, --help Print this information."
|
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() {
|
main() {
|
||||||
# clean up
|
# clean up
|
||||||
if [[ -d $SITE_DIR ]]; then
|
if [[ -d $SITE_DIR ]]; then
|
||||||
rm -rf "$SITE_DIR"
|
rm -rf "$SITE_DIR"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
_baseurl="$(grep '^baseurl:' "$_config" | sed "s/.*: *//;s/['\"]//g;s/#.*//")"
|
read_baseurl
|
||||||
|
|
||||||
# build
|
# build
|
||||||
JEKYLL_ENV=production bundle exec jekyll build \
|
JEKYLL_ENV=production bundle exec jekyll b \
|
||||||
--destination "$SITE_DIR$_baseurl" \
|
-d "$SITE_DIR$_baseurl" -c "$_config"
|
||||||
--config "$_config"
|
|
||||||
|
|
||||||
# test
|
# test
|
||||||
bundle exec htmlproofer "$SITE_DIR" \
|
bundle exec htmlproofer "$SITE_DIR" \
|
||||||
|
|
Loading…
Reference in a new issue