#!/bin/bash

PAGE_ROOT=${1:-"/"}
IS_PUBLISH_DEPLOYMENT=${2:-false}

PAGE_ROOT=$(echo "$PAGE_ROOT" | sed 's:/*$::')

if [ "$IS_PUBLISH_DEPLOYMENT" = true ]; then
    echo "Using publish deployment strategy"
    CONFIG_FILE="_config.yml"
else
    echo "Using draft deployment strategy"
    CONFIG_FILE="_config_draft.yml"
fi

echo "Using config file: $CONFIG_FILE"
echo "Config file contents:"
cat "$CONFIG_FILE"

echo "Publishing to page root: \"$PAGE_ROOT\""
bundle exec jekyll build -d public -b "$PAGE_ROOT" --config "$CONFIG_FILE"

echo "Build complete. Contents of public directory:"
ls -R public