Add Git functionality to deployBlog
This commit is contained in:
parent
d36df52eca
commit
7a0ec20985
@ -1,21 +1,62 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Usage:
|
||||
# <script> -path <path> [-noGit]
|
||||
# * <path>, if present, should point to the path to Hugo root
|
||||
# * -noGit will disable git operation
|
||||
|
||||
set -e
|
||||
|
||||
# -p <path>
|
||||
# $path should be the path to the root of the Hugo content
|
||||
while getopts p: flag
|
||||
# https://stackoverflow.com/a/52156612/1040915
|
||||
declare -A flags
|
||||
declare -A booleans
|
||||
args=()
|
||||
|
||||
while [ "$1" ];
|
||||
do
|
||||
case "${flag}" in
|
||||
p) path=${OPTARG};;
|
||||
esac
|
||||
arg=$1
|
||||
if [ "${1:0:1}" == "-" ]
|
||||
then
|
||||
shift
|
||||
rev=$(echo "$arg" | rev)
|
||||
if [ -z "$1" ] || [ "${1:0:1}" == "-" ] || [ "${rev:0:1}" == ":" ]
|
||||
then
|
||||
bool=$(echo ${arg:1} | sed s/://g)
|
||||
booleans[$bool]=true
|
||||
# echo \"$bool\" is boolean
|
||||
else
|
||||
value=$1
|
||||
flags[${arg:1}]=$value
|
||||
shift
|
||||
# echo \"$arg\" is flag with value \"$value\"
|
||||
fi
|
||||
else
|
||||
args+=("$arg")
|
||||
shift
|
||||
# echo \"$arg\" is an arg
|
||||
fi
|
||||
done
|
||||
|
||||
if [ -z "$path" ]; then
|
||||
echo "Path not set"
|
||||
exit 1
|
||||
if [ -z ${flags["path"]} ]; then
|
||||
path="blog";
|
||||
else
|
||||
path=${flags["path"]};
|
||||
fi
|
||||
|
||||
# https://stackoverflow.com/a/56841359/1040915
|
||||
if [[ -z "${booleans['noGit']:-}" ]]; then
|
||||
# This assumes that the blog content is within the Git repo which contains the script location.
|
||||
# https://unix.stackexchange.com/a/155077/30828
|
||||
if [ -n "$(git status --porcelain)" ]; then
|
||||
echo "Working directory not clean - aborting";
|
||||
exit
|
||||
fi
|
||||
|
||||
git push
|
||||
fi
|
||||
exit
|
||||
|
||||
|
||||
hugo --quiet --source $path
|
||||
|
||||
cp -r $path/public ./blogContent
|
||||
|
Loading…
x
Reference in New Issue
Block a user