1
0
mirror of https://github.com/cotes2020/jekyll-theme-chirpy.git synced 2025-12-18 05:41:31 +00:00

Improve the Shell code style.

This commit is contained in:
Cotes Chung
2020-08-19 17:05:58 +08:00
parent 038bccb3ca
commit 10ab9d3364
8 changed files with 86 additions and 85 deletions

View File

@@ -10,11 +10,11 @@ set -eu
CMD="JEKYLL_ENV=production bundle exec jekyll b"
WORK_DIR=$(dirname $(dirname $(realpath "$0")))
WORK_DIR="$(dirname $(dirname $(realpath "$0")))"
CONTAINER=${WORK_DIR}/.container
CONTAINER="${WORK_DIR}/.container"
DEST=${WORK_DIR}/_site
DEST="${WORK_DIR}/_site"
_help() {
@@ -30,44 +30,44 @@ _help() {
_init() {
cd $WORK_DIR
cd "$WORK_DIR"
if [[ -d $CONTAINER ]]; then
rm -rf $CONTAINER
if [[ -d "$CONTAINER" ]]; then
rm -rf "$CONTAINER"
fi
if [[ -d _site ]]; then
if [[ -d "_site" ]]; then
jekyll clean
fi
local _temp=$(mktemp -d)
cp -r * $_temp
cp -r .git $_temp
mv $_temp $CONTAINER
local _temp="$(mktemp -d)"
cp -r ./* "$_temp"
cp -r ./.git "$_temp"
mv "$_temp" "$CONTAINER"
}
_build() {
cd $CONTAINER
cd "$CONTAINER"
echo "$ cd $(pwd)"
bash _scripts/sh/create_pages.sh
bash _scripts/sh/dump_lastmod.sh
bash "_scripts/sh/create_pages.sh"
bash "_scripts/sh/dump_lastmod.sh"
CMD+=" -d ${DEST}"
CMD+=" -d $DEST"
echo "\$ $CMD"
eval $CMD
eval "$CMD"
echo -e "\nBuild success, the site files have been placed in '${DEST}'."
if [[ -d ${DEST}/.git ]]; then
if [[ ! -z $(git -C $DEST status -s) ]]; then
git -C $DEST add .
git -C $DEST commit -m "[Automation] Update site files." -q
if [[ -d "${DEST}/.git" ]]; then
if [[ ! -z $(git -C "$DEST" status -s) ]]; then
git -C "$DEST" add .
git -C "$DEST" commit -m "[Automation] Update site files." -q
echo -e "\nPlease push the changes of $DEST to remote master branch.\n"
fi
fi
cd .. && rm -rf $CONTAINER
cd .. && rm -rf "$CONTAINER"
}
@@ -95,8 +95,8 @@ main() {
shift
;;
-d|--destination)
_check_unset $2
DEST=$(realpath $2)
_check_unset "$2"
DEST="$(realpath "$2")"
shift;
shift;
;;

View File

@@ -14,17 +14,18 @@ PAGES_BRANCH="gh-pages"
_no_branch=false
if [[ -z `git branch -av | grep $PAGES_BRANCH` ]]; then
if [[ -z $(git branch -av | grep "$PAGES_BRANCH") ]]; then
_no_branch=true
git checkout -b $PAGES_BRANCH
git checkout -b "$PAGES_BRANCH"
else
git checkout $PAGES_BRANCH
git checkout "$PAGES_BRANCH"
fi
mv _site ../
mv .git ../
rm -rf * && rm -rf .[^.] .??*
rm -rf ./*
rm -rf .[^.] .??*
mv ../_site/* .
mv ../.git .

View File

@@ -13,12 +13,12 @@ CATEGORIES=false
TAGS=false
LASTMOD=false
WORK_DIR=$(dirname $(dirname $(realpath "$0")))
WORK_DIR="$(dirname $(dirname $(realpath "$0")))"
check_status() {
local _change=$(git status . -s)
if [[ ! -z ${_change} ]]; then
if [[ ! -z $_change ]]; then
echo "Warning: Commit the following changes first:"
echo "$_change"
exit 1
@@ -81,7 +81,7 @@ push() {
main() {
cd $WORK_DIR
cd "$WORK_DIR"
check_status

View File

@@ -15,12 +15,12 @@
set -eu
WORK_DIR=$(dirname $(dirname $(realpath "$0")))
URL_FILE=${WORK_DIR}/_config.yml
PV_CACHE=${WORK_DIR}/assets/js/data/pageviews.json
WORK_DIR="$(dirname $(dirname $(realpath "$0")))"
URL_FILE="${WORK_DIR}/_config.yml"
PV_CACHE="${WORK_DIR}/assets/js/data/pageviews.json"
PROXY_URL=$(grep "proxy_endpoint:" $URL_FILE | sed "s/.*: '//g;s/'.*//")
PROXY_URL="$(grep "proxy_endpoint:" "$URL_FILE" | sed "s/.*: '//g;s/'.*//")"
wget $PROXY_URL -O $PV_CACHE
wget "$PROXY_URL" -O "$PV_CACHE"
echo "ls $PV_CACHE"

View File

@@ -41,21 +41,21 @@ _cleanup() {
jekyll clean
fi
rm -rf ${WORK_DIR}/${CONTAINER}
rm -rf "${WORK_DIR}/${CONTAINER}"
ps aux | grep fswatch | awk '{print $2}' | xargs kill -9 > /dev/null 2>&1
}
_init() {
if [[ -d ${WORK_DIR}/${CONTAINER} ]]; then
rm -rf ${WORK_DIR}/${CONTAINER}
if [[ -d "${WORK_DIR}/${CONTAINER}" ]]; then
rm -rf "${WORK_DIR}/${CONTAINER}"
fi
temp=$(mktemp -d)
cp -r ${WORK_DIR}/* $temp
cp -r ${WORK_DIR}/.git $temp
mv $temp ${WORK_DIR}/${CONTAINER}
temp="$(mktemp -d)"
cp -r "$WORK_DIR"/* "$temp"
cp -r "${WORK_DIR}/.git" "$temp"
mv "$temp" "${WORK_DIR}/${CONTAINER}"
trap _cleanup INT
}
@@ -70,7 +70,7 @@ _check_unset() {
_check_command() {
if [[ -z $(command -v $1) ]]; then
if [[ -z $(command -v "$1") ]]; then
echo "Error: command '$1' not found !"
echo "Hint: Get '$1' on <$2>"
exit 1
@@ -81,16 +81,16 @@ _check_command() {
main() {
_init
cd ${WORK_DIR}/${CONTAINER}
cd "${WORK_DIR}/${CONTAINER}"
bash _scripts/sh/create_pages.sh
bash _scripts/sh/dump_lastmod.sh
if [[ $realtime = true ]]; then
fswatch -0 -e "\\$CONTAINER" -e "\.git" ${WORK_DIR} | xargs -0 -I {} bash ./${SYNC_TOOL} {} $WORK_DIR . &
fswatch -0 -e "\\$CONTAINER" -e "\.git" "$WORK_DIR" | xargs -0 -I {} bash "./${SYNC_TOOL}" {} "$WORK_DIR" . &
fi
echo "\$ $cmd"
eval $cmd
eval "$cmd"
}
@@ -99,20 +99,20 @@ do
opt="$1"
case $opt in
-H|--host)
_check_unset $2
_check_unset "$2"
cmd+=" -H $2"
shift # past argument
shift # past value
;;
-P|--port)
_check_unset $2
_check_unset "$2"
cmd+=" -P $2"
shift
shift
;;
-b|--baseurl)
_check_unset $2
if [[ $2 == \/* ]]
_check_unset "$2"
if [[ "$2" == \/* ]]
then
cmd+=" -b $2"
else
@@ -127,7 +127,7 @@ do
shift
;;
-r|--realtime)
_check_command fswatch 'http://emcrisostomo.github.io/fswatch/'
_check_command fswatch "http://emcrisostomo.github.io/fswatch/"
realtime=true
shift
;;