mirror of
https://github.com/cotes2020/jekyll-theme-chirpy.git
synced 2025-12-18 05:41:31 +00:00
Moved the script tools.
This commit is contained in:
122
tools/build.sh
Executable file
122
tools/build.sh
Executable file
@@ -0,0 +1,122 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Build jekyll site and store site files in ./_site
|
||||
# © 2019 Cotes Chung
|
||||
# Published under MIT License
|
||||
|
||||
set -eu
|
||||
|
||||
CMD="JEKYLL_ENV=production bundle exec jekyll b"
|
||||
|
||||
WORK_DIR=$(dirname $(dirname $(realpath "$0")))
|
||||
|
||||
CONTAINER=${WORK_DIR}/.container
|
||||
|
||||
DEST=${WORK_DIR}/_site
|
||||
|
||||
|
||||
help() {
|
||||
echo "Usage:"
|
||||
echo
|
||||
echo " bash build.sh [options]"
|
||||
echo
|
||||
echo "Options:"
|
||||
echo " -b, --baseurl <URL> The site relative url that start with slash, e.g. '/project'"
|
||||
echo " -h, --help Print the help information"
|
||||
echo " -d, --destination <DIR> Destination directory (defaults to ./_site)"
|
||||
}
|
||||
|
||||
|
||||
init() {
|
||||
cd $WORK_DIR
|
||||
|
||||
if [[ -d $CONTAINER ]]; then
|
||||
rm -rf $CONTAINER
|
||||
fi
|
||||
|
||||
if [[ -d _site ]]; then
|
||||
jekyll clean
|
||||
fi
|
||||
|
||||
temp=$(mktemp -d)
|
||||
cp -r * $temp
|
||||
cp -r .git $temp
|
||||
mv $temp $CONTAINER
|
||||
}
|
||||
|
||||
|
||||
build() {
|
||||
cd $CONTAINER
|
||||
|
||||
echo "$ cd $(pwd)"
|
||||
python _scripts/py/init_all.py
|
||||
|
||||
CMD+=" -d ${DEST}"
|
||||
echo "\$ $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
|
||||
echo -e "\nPlease push the changes of $DEST to remote master branch.\n"
|
||||
fi
|
||||
fi
|
||||
|
||||
cd .. && rm -rf $CONTAINER
|
||||
}
|
||||
|
||||
|
||||
check_unset() {
|
||||
if [[ -z ${1:+unset} ]]
|
||||
then
|
||||
help
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
main() {
|
||||
while [[ $# -gt 0 ]]
|
||||
do
|
||||
opt="$1"
|
||||
case $opt in
|
||||
-b|--baseurl)
|
||||
check_unset $2
|
||||
|
||||
if [[ $2 == \/* ]]
|
||||
then
|
||||
CMD+=" -b $2"
|
||||
else
|
||||
help
|
||||
exit 1
|
||||
fi
|
||||
|
||||
shift
|
||||
shift
|
||||
;;
|
||||
-d|--destination)
|
||||
check_unset $2
|
||||
DEST=$(realpath $2)
|
||||
shift;
|
||||
shift;
|
||||
;;
|
||||
-h|--help)
|
||||
help
|
||||
exit 0
|
||||
;;
|
||||
*) # unknown option
|
||||
help
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
init
|
||||
|
||||
build
|
||||
}
|
||||
|
||||
|
||||
main
|
||||
83
tools/init.sh
Executable file
83
tools/init.sh
Executable file
@@ -0,0 +1,83 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Initial the Categories/Tags pages and Lastmod for posts.
|
||||
# © 2019 Cotes Chung
|
||||
# Published under MIT License
|
||||
|
||||
set -eu
|
||||
|
||||
CATEGORIES=false
|
||||
TAGS=false
|
||||
LASTMOD=false
|
||||
|
||||
WORK_DIR=$(dirname $(dirname $(realpath "$0")))
|
||||
|
||||
check_status() {
|
||||
if [[ ! -z $(git status -s) ]]; then
|
||||
echo "Warning: Commit the changes of the repository first."
|
||||
git status -s
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
update_files() {
|
||||
python _scripts/py/init_all.py
|
||||
find . | grep -E "(__pycache__|\.pyc|\.pyo$)" | xargs rm -rf
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
|
||||
if [[ ! -z $(git status _posts -s) ]]; then
|
||||
git add _posts/
|
||||
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)."
|
||||
git commit -m "[Automation] $msg"
|
||||
else
|
||||
msg="Nothing changed."
|
||||
fi
|
||||
|
||||
echo $msg
|
||||
}
|
||||
|
||||
|
||||
main() {
|
||||
|
||||
cd $WORK_DIR
|
||||
|
||||
check_status
|
||||
|
||||
update_files
|
||||
|
||||
commit
|
||||
}
|
||||
|
||||
main
|
||||
23
tools/pv.sh
Executable file
23
tools/pv.sh
Executable file
@@ -0,0 +1,23 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Fetch Google Analytics Pageviews reporting cache
|
||||
# and save as 'assets/data/pagevies.json'
|
||||
#
|
||||
# Requirement:
|
||||
# - jq
|
||||
# - wget
|
||||
#
|
||||
# © 2019 Cotes Chung
|
||||
# MIT Licensed
|
||||
|
||||
|
||||
set -eu
|
||||
|
||||
WORK_DIR=$(dirname $(dirname $(realpath "$0")))
|
||||
URL_FILE=${WORK_DIR}/assets/data/proxy.json
|
||||
PV_CACHE=${WORK_DIR}/assets/data/pageviews.json
|
||||
|
||||
|
||||
PROXY_URL=$(jq -r '.proxyUrl' $URL_FILE)
|
||||
|
||||
wget $PROXY_URL -O $PV_CACHE
|
||||
139
tools/run.sh
Executable file
139
tools/run.sh
Executable file
@@ -0,0 +1,139 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Run jekyll site at http://127.0.0.1:4000
|
||||
#
|
||||
# Requirement:
|
||||
# Option '-r, --realtime' needs fswatch › http://emcrisostomo.github.io/fswatch/
|
||||
#
|
||||
# © 2019 Cotes Chung
|
||||
# Published under MIT License
|
||||
|
||||
set -eu
|
||||
|
||||
WORK_DIR=$(dirname $(dirname $(realpath "$0")))
|
||||
|
||||
CONTAINER=.container
|
||||
SYNC_TOOL=_scripts/sh/sync_monitor.sh
|
||||
|
||||
cmd="bundle exec jekyll s"
|
||||
realtime=false
|
||||
|
||||
|
||||
help() {
|
||||
echo "Usage:"
|
||||
echo
|
||||
echo " bash run.sh [options]"
|
||||
echo
|
||||
echo "Options:"
|
||||
echo " -H, --host <HOST> Host to bind to"
|
||||
echo " -P, --port <PORT> Port to listen on"
|
||||
echo " -b, --baseurl <URL> The site relative url that start with slash, e.g. '/project'"
|
||||
echo " -h, --help Print the help information"
|
||||
echo " -t, --trace Show the full backtrace when an error occurs"
|
||||
echo " -r, --realtime Make the modified content updated in real time"
|
||||
}
|
||||
|
||||
|
||||
cleanup() {
|
||||
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}
|
||||
fi
|
||||
|
||||
temp=$(mktemp -d)
|
||||
cp -r ${WORK_DIR}/* $temp
|
||||
cp -r ${WORK_DIR}/.git $temp
|
||||
mv $temp ${WORK_DIR}/${CONTAINER}
|
||||
|
||||
trap cleanup INT
|
||||
}
|
||||
|
||||
|
||||
check_unset() {
|
||||
if [[ -z ${1:+unset} ]]; then
|
||||
help
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
check_command() {
|
||||
if [[ -z $(command -v $1) ]]; then
|
||||
echo "Error: command '$1' not found !"
|
||||
echo "Hint: Get '$1' on <$2>"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
main() {
|
||||
init
|
||||
|
||||
cd ${WORK_DIR}/${CONTAINER}
|
||||
python _scripts/py/init_all.py
|
||||
|
||||
if [[ $realtime = true ]]; then
|
||||
fswatch -0 -e "\\$CONTAINER" -e "\.git" ${WORK_DIR} | xargs -0 -I {} bash ./${SYNC_TOOL} {} $WORK_DIR . &
|
||||
fi
|
||||
|
||||
echo "\$ $cmd"
|
||||
eval $cmd
|
||||
}
|
||||
|
||||
|
||||
while (( $# ))
|
||||
do
|
||||
opt="$1"
|
||||
case $opt in
|
||||
-H|--host)
|
||||
check_unset $2
|
||||
cmd+=" -H $2"
|
||||
shift # past argument
|
||||
shift # past value
|
||||
;;
|
||||
-P|--port)
|
||||
check_unset $2
|
||||
cmd+=" -P $2"
|
||||
shift
|
||||
shift
|
||||
;;
|
||||
-b|--baseurl)
|
||||
check_unset $2
|
||||
if [[ $2 == \/* ]]
|
||||
then
|
||||
cmd+=" -b $2"
|
||||
else
|
||||
help
|
||||
exit 1
|
||||
fi
|
||||
shift
|
||||
shift
|
||||
;;
|
||||
-t|--trace)
|
||||
cmd+=" -t"
|
||||
shift
|
||||
;;
|
||||
-r|--realtime)
|
||||
check_command fswatch 'http://emcrisostomo.github.io/fswatch/'
|
||||
realtime=true
|
||||
shift
|
||||
;;
|
||||
-h|--help)
|
||||
help
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
# unknown option
|
||||
help
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
main
|
||||
Reference in New Issue
Block a user