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

Replace python with bash.

This commit is contained in:
Cotes Chung
2020-04-10 03:15:51 +08:00
parent b30d673367
commit 99aadd61c1
15 changed files with 336 additions and 556 deletions

View File

@@ -17,7 +17,7 @@ CONTAINER=${WORK_DIR}/.container
DEST=${WORK_DIR}/_site
help() {
_help() {
echo "Usage:"
echo
echo " bash build.sh [options]"
@@ -29,7 +29,7 @@ help() {
}
init() {
_init() {
cd $WORK_DIR
if [[ -d $CONTAINER ]]; then
@@ -40,18 +40,19 @@ init() {
jekyll clean
fi
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() {
_build() {
cd $CONTAINER
echo "$ cd $(pwd)"
python _scripts/py/init_all.py
bash _scripts/sh/create_pages.sh
bash _scripts/sh/dump_lastmod.sh
CMD+=" -d ${DEST}"
echo "\$ $CMD"
@@ -70,10 +71,10 @@ build() {
}
check_unset() {
_check_unset() {
if [[ -z ${1:+unset} ]]
then
help
_help
exit 1
fi
}
@@ -85,36 +86,36 @@ main() {
opt="$1"
case $opt in
-b|--baseurl)
check_unset $2
_check_unset $2
if [[ $2 == \/* ]]
then
CMD+=" -b $2"
else
help
_help
exit 1
fi
shift
shift
;;
-d|--destination)
check_unset $2
_check_unset $2
DEST=$(realpath $2)
shift;
shift;
;;
-h|--help)
help
_help
exit 0
;;
*) # unknown option
help
_help
exit 1
;;
esac
done
init
build
_init
_build
}
main "$@"

View File

@@ -15,16 +15,26 @@ LASTMOD=false
WORK_DIR=$(dirname $(dirname $(realpath "$0")))
check_status() {
if [[ ! -z $(git status _posts -s) ]]; then
echo "Warning: Commit the changes of the directory '_posts' first."
git status -s | grep '_posts'
exit 1
fi
local _watching_dirs=(
"_post"
"_data")
for i in "${!_watching_dirs[@]}"
do
local _dir=${_watching_dirs[${i}]}
if [[ ! -z $(git status $_dir -s) ]]; then
echo "Warning: Commit the changes of the directory '$_dir' first."
git status -s | grep $_dir
exit 1
fi
done
}
update_files() {
python _scripts/py/init_all.py
bash _scripts/sh/create_pages.sh
bash _scripts/sh/dump_lastmod.sh
find . | grep -E "(__pycache__|\.pyc|\.pyo$)" | xargs rm -rf
}
@@ -49,8 +59,8 @@ commit() {
TAGS=true
fi
if [[ ! -z $(git status _posts -s) ]]; then
git add _posts/
if [[ ! -z $(git status _data -s) ]]; then
git add _data
if [[ $CATEGORIES = true || $TAGS = true ]]; then
msg+=","
else

View File

@@ -21,7 +21,7 @@ cmd="bundle exec jekyll s"
realtime=false
help() {
_help() {
echo "Usage:"
echo
echo " bash run.sh [options]"
@@ -36,7 +36,7 @@ help() {
}
cleanup() {
_cleanup() {
if [[ -d _site || -d .jekyll-cache ]]; then
jekyll clean
fi
@@ -46,7 +46,7 @@ cleanup() {
}
init() {
_init() {
if [[ -d ${WORK_DIR}/${CONTAINER} ]]; then
rm -rf ${WORK_DIR}/${CONTAINER}
@@ -57,19 +57,19 @@ init() {
cp -r ${WORK_DIR}/.git $temp
mv $temp ${WORK_DIR}/${CONTAINER}
trap cleanup INT
trap _cleanup INT
}
check_unset() {
_check_unset() {
if [[ -z ${1:+unset} ]]; then
help
_help
exit 1
fi
}
check_command() {
_check_command() {
if [[ -z $(command -v $1) ]]; then
echo "Error: command '$1' not found !"
echo "Hint: Get '$1' on <$2>"
@@ -79,10 +79,11 @@ check_command() {
main() {
init
_init
cd ${WORK_DIR}/${CONTAINER}
python _scripts/py/init_all.py
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 . &
@@ -98,24 +99,24 @@ 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
_check_unset $2
if [[ $2 == \/* ]]
then
cmd+=" -b $2"
else
help
_help
exit 1
fi
shift
@@ -126,20 +127,21 @@ do
shift
;;
-r|--realtime)
check_command fswatch 'http://emcrisostomo.github.io/fswatch/'
_check_command fswatch 'http://emcrisostomo.github.io/fswatch/'
realtime=true
shift
;;
-h|--help)
help
_help
exit 0
;;
*)
# unknown option
help
_help
exit 1
;;
esac
done
main