#!/bin/sh validate_hugo () { # Exit with error if hugo is not installed if ! hash hugo 2>/dev/null ; then echo "Error: After Dark requires Hugo version 0.44 or greater" >&2; exit 1 fi # Exit with error if not minimum required hugo version re="v(0\d*\.([4-9][4-9]|[5-9])|[1-9]).*" if ! hugo version | grep -qE "$re" ; then echo "Error: After Dark requires Hugo version 0.44 or greater" >&2; exit 1 fi } create_site_dir () { SITE_DIR="flying-toasters" if [ "$1" != "" ] ; then SITE_DIR="$1" fi SITE_DIR_ABS="$PWD/$SITE_DIR" mkdir -p "$SITE_DIR" } create_site () { echo "Creating a new Hugo site ..." hugo new site "$SITE_DIR" 1>/dev/null cd "$SITE_DIR" || exit 1 } download_theme () { echo "Downloading the latest version of After Dark ..." LATEST_META=$(wget -qO - https://registry.npmjs.org/after-dark/latest) vers=$(echo "$LATEST_META" | egrep -o "\"version\".*[^,]*," | cut -d ',' -f1 | cut -d ':' -f2 | tr -d '" ') mkdir -p themes/after-dark wget -qO - https://registry.npmjs.org/after-dark/-/after-dark-"$vers".tgz | tar --strip-components=1 -xz -C themes/after-dark echo "Version $vers downloaded to $SITE_DIR/themes/after-dark" } download_module () { [ -z "$1" ] && { echo "Error: Attempt to download undefined module" >&2; exit 1; } echo "Downloading $1 module for After Dark ..." meta=$(wget -qO - https://registry.npmjs.org/"$1"/latest) vers=$(echo "$meta" | egrep -o "\"version\".*[^,]*," | cut -d ',' -f1 | cut -d ':' -f2 | tr -d '" ') mkdir -p themes/"$1" wget -qO - https://registry.npmjs.org/"$1"/-/"$1"-"$vers".tgz | tar --strip-components=1 -xz -C themes/"$1" echo "Version $vers downloaded to $SITE_DIR/themes/$1" } configure_theme () { echo "Configuring basic After Dark theme settings ..." tee "config.toml" > /dev/null <