2020-01-01 20:21:43 +03:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
2020-06-26 13:26:50 +03:00
|
|
|
# Initial the Categories/Tags pages and Lastmod for posts and then push to remote
|
|
|
|
#
|
2020-01-02 16:17:49 +03:00
|
|
|
# v2.0
|
|
|
|
# https://github.com/cotes2020/jekyll-theme-chirpy
|
2020-01-01 20:21:43 +03:00
|
|
|
# © 2019 Cotes Chung
|
|
|
|
# Published under MIT License
|
|
|
|
|
|
|
|
set -eu
|
|
|
|
|
|
|
|
CATEGORIES=false
|
|
|
|
TAGS=false
|
|
|
|
LASTMOD=false
|
|
|
|
|
|
|
|
WORK_DIR=$(dirname $(dirname $(realpath "$0")))
|
|
|
|
|
|
|
|
check_status() {
|
2020-06-26 13:26:50 +03:00
|
|
|
local _change=$(git status . -s)
|
|
|
|
|
|
|
|
if [[ ! -z ${_change} ]]; then
|
2020-07-13 06:20:07 +03:00
|
|
|
echo "Warning: Commit the following changes first:"
|
2020-06-26 13:26:50 +03:00
|
|
|
echo "$_change"
|
|
|
|
exit 1
|
|
|
|
fi
|
2020-01-01 20:21:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
update_files() {
|
2020-04-09 22:15:51 +03:00
|
|
|
bash _scripts/sh/create_pages.sh
|
|
|
|
bash _scripts/sh/dump_lastmod.sh
|
2020-01-01 20:21:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
commit() {
|
|
|
|
msg="Updated"
|
|
|
|
|
|
|
|
if [[ ! -z $(git status categories -s) ]]; then
|
|
|
|
git add categories/
|
|
|
|
msg+=" the Categories"
|
|
|
|
CATEGORIES=true
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ ! -z $(git status tags -s) ]]; then
|
|
|
|
git add tags/
|
|
|
|
if [[ $CATEGORIES = true ]]; then
|
|
|
|
msg+=","
|
|
|
|
else
|
|
|
|
msg+=" the"
|
|
|
|
fi
|
|
|
|
msg+=" Tags"
|
|
|
|
TAGS=true
|
|
|
|
fi
|
|
|
|
|
2020-04-09 22:15:51 +03:00
|
|
|
if [[ ! -z $(git status _data -s) ]]; then
|
|
|
|
git add _data
|
2020-01-01 20:21:43 +03:00
|
|
|
if [[ $CATEGORIES = true || $TAGS = true ]]; then
|
|
|
|
msg+=","
|
|
|
|
else
|
|
|
|
msg+=" the"
|
|
|
|
fi
|
|
|
|
msg+=" Lastmod"
|
|
|
|
LASTMOD=true
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ $CATEGORIES = true || $TAGS = true || $LASTMOD = true ]]; then
|
|
|
|
msg+=" for post(s)."
|
2020-06-26 13:26:50 +03:00
|
|
|
git commit -m "[Automation] $msg" -q
|
2020-01-01 20:21:43 +03:00
|
|
|
else
|
|
|
|
msg="Nothing changed."
|
|
|
|
fi
|
|
|
|
|
2020-06-26 13:26:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
push() {
|
|
|
|
git push origin master -q
|
|
|
|
echo "[INFO] Published successfully!"
|
2020-01-01 20:21:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
main() {
|
|
|
|
|
|
|
|
cd $WORK_DIR
|
|
|
|
|
|
|
|
check_status
|
|
|
|
|
|
|
|
update_files
|
|
|
|
|
|
|
|
commit
|
2020-06-26 13:26:50 +03:00
|
|
|
|
|
|
|
push
|
2020-01-01 20:21:43 +03:00
|
|
|
}
|
|
|
|
|
2020-06-26 13:26:50 +03:00
|
|
|
|
2020-01-01 20:21:43 +03:00
|
|
|
main
|