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

Pretty shell format.

This commit is contained in:
Cotes Chung
2020-09-01 14:54:29 +08:00
parent 252e33b502
commit c473771af4
7 changed files with 50 additions and 88 deletions

View File

@@ -7,7 +7,6 @@
# © 2020 Cotes Chung
# Published under MIT License
set -eu
PAGES_BRANCH="gh-pages"
@@ -28,11 +27,11 @@ backup() {
mv _site "$_backup_dir"
mv .git "$_backup_dir"
# When adding custom domain from Github website,
# When adding custom domain from Github website,
# the CANME only exist on `gh-pages` branch
if [[ -f CNAME ]]; then
if [[ -f CNAME ]]; then
mv CNAME "$_backup_dir"
fi
fi
}
flush() {
@@ -51,7 +50,7 @@ deoply() {
git add -A
git commit -m "[Automation] Site update No.${GITHUB_RUN_NUMBER}"
if [[ $_no_branch = true ]]; then
if $_no_branch; then
git push -u origin "$PAGES_BRANCH"
else
git push -f

View File

@@ -9,7 +9,6 @@
set -eu
ACTIONS_WORKFLOW=pages-deploy.yml
help() {
@@ -26,24 +25,23 @@ check_init() {
local _has_inited=false
if [[ -d .github ]]; then
if [[ -f .github/workflows/$ACTIONS_WORKFLOW
&& $(find .github/workflows/ -type f -name "*.yml" | wc -l) == 1 ]]; then
if [[ -f .github/workflows/$ACTIONS_WORKFLOW && \
$(find .github/workflows/ -type f -name "*.yml" | wc -l) == 1 ]]; then
_has_inited=true
fi
else
_has_inited=true
fi
if [[ $_has_inited = true ]]; then
if $_has_inited; then
echo "Already initialized."
exit 0
fi
}
init_files() {
if [[ $_no_gh = true ]]; then
if $_no_gh; then
rm -rf .github
else
mv .github/workflows/$ACTIONS_WORKFLOW.hook .
@@ -55,34 +53,32 @@ init_files() {
rm -f .travis.yml
rm -rf _posts/* docs
git add -A && git add .github -f
git add -A && git add .github -f
git commit -m "[Automation] Initialize the environment." -q
echo "[INFO] Initialization successful!"
}
check_init
_no_gh=false
while (( $# ))
do
while (($#)); do
opt="$1"
case $opt in
--no-gh)
_no_gh=true
shift
;;
-h|--help)
-h | --help)
help
exit 0
;;
*)
# unknown option
help
exit 1
;;
*)
# unknown option
help
exit 1
;;
esac
done

View File

@@ -15,7 +15,6 @@ LASTMOD=false
WORK_DIR="$(dirname "$(dirname "$(realpath "$0")")")"
check_status() {
local _change=$(git status . -s)
@@ -26,13 +25,11 @@ check_status() {
fi
}
update_files() {
bash _scripts/sh/create_pages.sh
bash _scripts/sh/dump_lastmod.sh
}
commit() {
msg="Updated"
@@ -44,7 +41,7 @@ commit() {
if [[ ! -z $(git status tags -s) ]]; then
git add tags/
if [[ $CATEGORIES = true ]]; then
if $CATEGORIES; then
msg+=","
else
msg+=" the"
@@ -53,9 +50,9 @@ commit() {
TAGS=true
fi
if [[ ! -z $(git status _data -s) ]]; then
if [[ -n $(git status _data -s) ]]; then
git add _data
if [[ $CATEGORIES = true || $TAGS = true ]]; then
if $CATEGORIES || $TAGS; then
msg+=","
else
msg+=" the"
@@ -64,7 +61,7 @@ commit() {
LASTMOD=true
fi
if [[ $CATEGORIES = true || $TAGS = true || $LASTMOD = true ]]; then
if $CATEGORIES || $TAGS || $LASTMOD; then
msg+=" for post(s)."
git commit -m "[Automation] $msg" -q
else
@@ -73,13 +70,11 @@ commit() {
}
push() {
git push origin master -q
echo "[INFO] Published successfully!"
}
main() {
cd "$WORK_DIR"
@@ -93,5 +88,4 @@ main() {
push
}
main

View File

@@ -20,7 +20,6 @@ SYNC_TOOL=_scripts/sh/sync_monitor.sh
cmd="bundle exec jekyll s -l -o"
realtime=false
_help() {
echo "Usage:"
echo
@@ -35,7 +34,6 @@ _help() {
echo " -r, --realtime Make the modified content updated in real time"
}
_cleanup() {
if [[ -d _site || -d .jekyll-cache ]]; then
jekyll clean
@@ -45,7 +43,6 @@ _cleanup() {
ps aux | grep fswatch | awk '{print $2}' | xargs kill -9 > /dev/null 2>&1
}
_init() {
if [[ -d "${WORK_DIR}/${CONTAINER}" ]]; then
@@ -60,7 +57,6 @@ _init() {
trap _cleanup INT
}
_check_unset() {
if [[ -z ${1:+unset} ]]; then
_help
@@ -68,7 +64,6 @@ _check_unset() {
fi
}
_check_command() {
if [[ -z $(command -v "$1") ]]; then
echo "Error: command '$1' not found !"
@@ -77,7 +72,6 @@ _check_command() {
fi
}
main() {
_init
@@ -85,7 +79,7 @@ main() {
bash _scripts/sh/create_pages.sh
bash _scripts/sh/dump_lastmod.sh
if [[ $realtime = true ]]; then
if $realtime; then
fswatch -0 -e "/\..*" "$WORK_DIR" | xargs -0 -I {} bash "./${SYNC_TOOL}" {} "$WORK_DIR" . &
fi
@@ -93,27 +87,24 @@ main() {
eval "$cmd"
}
while (( $# ))
do
while (($#)); do
opt="$1"
case $opt in
-H|--host)
-H | --host)
_check_unset "$2"
cmd+=" -H $2"
shift # past argument
shift # past value
;;
-P|--port)
-P | --port)
_check_unset "$2"
cmd+=" -P $2"
shift
shift
;;
-b|--baseurl)
-b | --baseurl)
_check_unset "$2"
if [[ "$2" == \/* ]]
then
if [[ "$2" == \/* ]]; then
cmd+=" -b $2"
else
_help
@@ -122,16 +113,16 @@ do
shift
shift
;;
-t|--trace)
-t | --trace)
cmd+=" -t"
shift
;;
-r|--realtime)
-r | --realtime)
_check_command fswatch "http://emcrisostomo.github.io/fswatch/"
realtime=true
shift
;;
-h|--help)
-h | --help)
_help
exit 0
;;
@@ -143,5 +134,4 @@ do
esac
done
main