Something went wrong. Try again.
Joseph Hale's Technical Blog
Something went wrong. Try again.
1.6 kB · 89 lines
at content
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990#!/usr/bin/env bash## Build and test the site content## Requirement: html-proofer, jekyll## Usage: See help informationset -euSITE_DIR="_site"_config="_config.yml"_baseurl=""help() { echo "Build and test the site content" echo echo "Usage:" echo echo " bash ./tools/test [options]" echo echo "Options:" echo ' -c, --config "<config_a[,config_b[...]]>" Specify config file(s)' 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 read_baseurl # build JEKYLL_ENV=production bundle exec jekyll b \ -d "$SITE_DIR$_baseurl" -c "$_config" # test bundle exec htmlproofer "$SITE_DIR" \ --disable-external=true \ --ignore-urls "/^http:\/\/127.0.0.1/,/^http:\/\/0.0.0.0/,/^http:\/\/localhost/"}while (($#)); do opt="$1" case $opt in -c | --config) _config="$2" shift shift ;; -h | --help) help exit 0 ;; *) # unknown option help exit 1 ;; esacdonemain