2022-08-14 00:47:30 +03:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
#
|
|
|
|
# Build and test the site content
|
|
|
|
#
|
|
|
|
# Requirement: html-proofer, jekyll
|
|
|
|
#
|
|
|
|
# Usage: See help information
|
|
|
|
|
|
|
|
set -eu
|
|
|
|
|
|
|
|
SITE_DIR="_site"
|
|
|
|
|
|
|
|
_config="_config.yml"
|
|
|
|
|
2022-10-06 14:47:29 +03:00
|
|
|
_baseurl=""
|
|
|
|
|
2022-08-14 00:47:30 +03:00
|
|
|
help() {
|
|
|
|
echo "Build and test the site content"
|
|
|
|
echo
|
|
|
|
echo "Usage:"
|
|
|
|
echo
|
2023-06-28 08:49:13 +03:00
|
|
|
echo " bash ./tools/test [options]"
|
2022-08-14 00:47:30 +03:00
|
|
|
echo
|
|
|
|
echo "Options:"
|
|
|
|
echo ' -c, --config "<config_a[,config_b[...]]>" Specify config file(s)'
|
|
|
|
echo " -h, --help Print this information."
|
|
|
|
}
|
|
|
|
|
2022-10-06 14:47:29 +03:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2022-08-14 00:47:30 +03:00
|
|
|
main() {
|
|
|
|
# clean up
|
|
|
|
if [[ -d $SITE_DIR ]]; then
|
|
|
|
rm -rf "$SITE_DIR"
|
|
|
|
fi
|
|
|
|
|
2022-10-06 14:47:29 +03:00
|
|
|
read_baseurl
|
2022-08-14 00:47:30 +03:00
|
|
|
|
|
|
|
# build
|
2022-10-06 14:47:29 +03:00
|
|
|
JEKYLL_ENV=production bundle exec jekyll b \
|
|
|
|
-d "$SITE_DIR$_baseurl" -c "$_config"
|
2022-08-14 00:47:30 +03:00
|
|
|
|
|
|
|
# test
|
|
|
|
bundle exec htmlproofer "$SITE_DIR" \
|
2024-05-11 09:08:39 +03:00
|
|
|
--disable-external \
|
2023-09-09 15:35:32 +03:00
|
|
|
--ignore-urls "/^http:\/\/127.0.0.1/,/^http:\/\/0.0.0.0/,/^http:\/\/localhost/"
|
2022-08-14 00:47:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
while (($#)); do
|
|
|
|
opt="$1"
|
|
|
|
case $opt in
|
|
|
|
-c | --config)
|
|
|
|
_config="$2"
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-h | --help)
|
|
|
|
help
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
# unknown option
|
|
|
|
help
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
main
|