Add Git functionality to deployBlog
This commit is contained in:
parent
d36df52eca
commit
7a0ec20985
@ -1,21 +1,62 @@
|
|||||||
#!/bin/bash
|
#!/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
|
set -e
|
||||||
|
|
||||||
# -p <path>
|
# https://stackoverflow.com/a/52156612/1040915
|
||||||
# $path should be the path to the root of the Hugo content
|
declare -A flags
|
||||||
while getopts p: flag
|
declare -A booleans
|
||||||
|
args=()
|
||||||
|
|
||||||
|
while [ "$1" ];
|
||||||
do
|
do
|
||||||
case "${flag}" in
|
arg=$1
|
||||||
p) path=${OPTARG};;
|
if [ "${1:0:1}" == "-" ]
|
||||||
esac
|
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
|
done
|
||||||
|
|
||||||
if [ -z "$path" ]; then
|
if [ -z ${flags["path"]} ]; then
|
||||||
echo "Path not set"
|
path="blog";
|
||||||
exit 1
|
else
|
||||||
|
path=${flags["path"]};
|
||||||
fi
|
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
|
hugo --quiet --source $path
|
||||||
|
|
||||||
cp -r $path/public ./blogContent
|
cp -r $path/public ./blogContent
|
||||||
|
Loading…
x
Reference in New Issue
Block a user