Moved the script tools.
This commit is contained in:
parent
5bb810875b
commit
3e004d1bf3
9 changed files with 237 additions and 209 deletions
15
README.md
15
README.md
|
@ -55,7 +55,8 @@ jekyll-theme-chirpy/
|
|||
├── _posts # posts stay here
|
||||
├── _scripts
|
||||
│ └── travis # CI stuff, remove it
|
||||
├── .travis.yml # remove it, too
|
||||
├── .travis.yml # remove this, too
|
||||
├── .github # remove
|
||||
├── assets
|
||||
├── tabs
|
||||
│ └── about.md # the ABOUT page
|
||||
|
@ -65,14 +66,10 @@ jekyll-theme-chirpy/
|
|||
├── LICENSE
|
||||
├── README.md
|
||||
├── _config.yml # configuration file
|
||||
├── build.sh # script tool
|
||||
├── run.sh # script tool
|
||||
├── init.sh # script tool
|
||||
├── pv.sh
|
||||
├── tools # script tools
|
||||
├── feed.xml
|
||||
├── index.html
|
||||
├── robots.txt
|
||||
├── search.json
|
||||
└── sitemap.xml
|
||||
```
|
||||
|
||||
|
@ -98,7 +95,7 @@ The `SITE_URL` was defined by variable `url` in file `_config.yml`.
|
|||
You may want to preview the site before publishing, so just run the script tool:
|
||||
|
||||
```terminal
|
||||
$ bash run.sh
|
||||
$ bash tools/run.sh
|
||||
```
|
||||
|
||||
>**Note**: The *Recent Update* list requires the latest git-log date of posts, thus make sure the changes in `_posts` have been committed before running this command.
|
||||
|
@ -123,7 +120,7 @@ By deploying your site in this way, you can push the source code to GitHub repos
|
|||
**2**. Commit the changes of your repository, then run the initialization script:
|
||||
|
||||
```console
|
||||
$ bash init.sh
|
||||
$ bash tools/init.sh
|
||||
```
|
||||
|
||||
It will automatically generates the *Latest Modified Date* and *Categories / Tags* page for the posts.
|
||||
|
@ -142,7 +139,7 @@ For security reasons, GitHub Pages runs on `safe` mode, which means the third-pa
|
|||
**2**. Build your site by:
|
||||
|
||||
```console
|
||||
$ bash build.sh -d /path/to/<username>.github.io/
|
||||
$ bash tools/build.sh -d /path/to/<username>.github.io/
|
||||
```
|
||||
|
||||
The build results will be stored in the root directory of `<username>.github.io` and don't forget to push the changes of `<username>.github.io` to branch `master` on GitHub.
|
||||
|
|
11
_config.yml
11
_config.yml
|
@ -8,7 +8,7 @@
|
|||
|
||||
title: Chirpy
|
||||
|
||||
description: 'A text-based Jekyll theme.'
|
||||
description: 'A text-focused Jekyll theme.'
|
||||
|
||||
# Replace with your domain, e.g. 'https://username.github.io'
|
||||
url: 'https://www.example.com'
|
||||
|
@ -56,7 +56,7 @@ disqus:
|
|||
shortname: 'disqus' # Change to your Disqus shortname. › https://help.disqus.com/en/articles/1717111-what-s-a-shortname
|
||||
comments: true # boolean type, the global switch for posts comments.
|
||||
|
||||
# The year your website was first run.
|
||||
# The year your website first ran.
|
||||
first_run: 2019
|
||||
|
||||
# boolean type, global switch for ToC in posts.
|
||||
|
@ -154,13 +154,10 @@ compress_html:
|
|||
envs: []
|
||||
|
||||
exclude:
|
||||
- vendor/ # Avoid Jekyll mistakenly read the vender directory on Travis-CI's VM .
|
||||
- vendor # Avoid Jekyll mistakenly read the vender directory on Travis-CI's VM .
|
||||
- Gemfile.lock
|
||||
- Gemfile
|
||||
- run.sh
|
||||
- build.sh
|
||||
- init.sh
|
||||
- pv.sh
|
||||
- tools
|
||||
|
||||
sitemap_exclude: # Sitemap will exclude the following items.
|
||||
- /norobots/
|
||||
|
|
|
@ -35,7 +35,8 @@ jekyll-theme-chirpy/
|
|||
├── _posts # posts stay here
|
||||
├── _scripts
|
||||
│ └── travis # CI stuff, remove it
|
||||
├── .travis.yml # remove it, too
|
||||
├── .travis.yml # remove this, too
|
||||
├── .github # remove
|
||||
├── assets
|
||||
├── tabs
|
||||
│ └── about.md # the ABOUT page
|
||||
|
@ -45,14 +46,10 @@ jekyll-theme-chirpy/
|
|||
├── LICENSE
|
||||
├── README.md
|
||||
├── _config.yml # configuration file
|
||||
├── build.sh # script tool
|
||||
├── run.sh # script tool
|
||||
├── init.sh # script tool
|
||||
├── pv.sh
|
||||
├── tools # script tools
|
||||
├── feed.xml
|
||||
├── index.html
|
||||
├── robots.txt
|
||||
├── search.json
|
||||
└── sitemap.xml
|
||||
```
|
||||
|
||||
|
@ -78,7 +75,7 @@ The `SITE_URL` was defined by variable `url` in file `_config.yml`.
|
|||
You may want to preview the site before publishing, so just run the script tool:
|
||||
|
||||
```terminal
|
||||
$ bash run.sh
|
||||
$ bash tools/run.sh
|
||||
```
|
||||
|
||||
>**Note**: The *Recent Update* list requires the latest git-log date of posts, thus make sure the changes in `_posts` have been committed before running this command.
|
||||
|
@ -102,7 +99,7 @@ By deploying your site in this way, you can push the source code to GitHub repos
|
|||
**2**. Commit the changes of your repository, then run the initialization script:
|
||||
|
||||
```console
|
||||
$ bash init.sh
|
||||
$ bash tools/init.sh
|
||||
```
|
||||
|
||||
It will automatically generates the *Latest Modified Date* and *Categories / Tags* page for the posts.
|
||||
|
@ -121,7 +118,7 @@ For security reasons, GitHub Pages runs on `safe` mode, which means the third-pa
|
|||
**2**. Build your site by:
|
||||
|
||||
```console
|
||||
$ bash build.sh -d /path/to/<username>.github.io/
|
||||
$ bash tools/build.sh -d /path/to/<username>.github.io/
|
||||
```
|
||||
|
||||
The build results will be stored in the root directory of `<username>.github.io` and don't forget to push the changes of `<username>.github.io` to branch `master` on GitHub.
|
||||
|
|
109
build.sh
109
build.sh
|
@ -1,109 +0,0 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# Build jekyll site and store site files in ./_site
|
||||
# © 2019 Cotes Chung
|
||||
# Published under MIT License
|
||||
|
||||
|
||||
CMD="JEKYLL_ENV=production bundle exec jekyll b"
|
||||
DEST=$(realpath '_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() {
|
||||
set -eu
|
||||
|
||||
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
|
||||
|
||||
}
|
||||
|
||||
|
||||
check_unset() {
|
||||
if [[ -z ${1:+unset} ]]
|
||||
then
|
||||
help
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
|
||||
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 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 '$(realpath $DEST)' to remote master branch.\n"
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
cd .. && rm -rf .container
|
62
init.sh
62
init.sh
|
@ -1,62 +0,0 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# Initial the Categories/Tags pages and Lastmod for posts.
|
||||
# © 2019 Cotes Chung
|
||||
# Published under MIT License
|
||||
|
||||
|
||||
CATEGORIES=false
|
||||
TAGS=false
|
||||
LASTMOD=false
|
||||
|
||||
set -eu
|
||||
|
||||
if [[ ! -z $(git status -s) ]]; then
|
||||
echo "Warning: Commit the changes of the repository first."
|
||||
git status -s
|
||||
exit 1
|
||||
fi
|
||||
|
||||
python _scripts/py/init_all.py
|
||||
|
||||
find . | grep -E "(__pycache__|\.pyc|\.pyo$)" | xargs rm -rf
|
||||
|
||||
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
|
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
|
|
@ -11,11 +11,13 @@
|
|||
# MIT Licensed
|
||||
|
||||
|
||||
URL_FILE=assets/data/proxy.json
|
||||
PV_CACHE=assets/data/pageviews.json
|
||||
|
||||
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
|
|
@ -8,14 +8,17 @@
|
|||
# © 2019 Cotes Chung
|
||||
# Published under MIT License
|
||||
|
||||
set -eu
|
||||
|
||||
WORK_DIR=$(dirname $(dirname $(realpath "$0")))
|
||||
|
||||
WORK_DIR=$PWD
|
||||
CONTAINER=.container
|
||||
SYNC_TOOL=_scripts/sh/sync_monitor.sh
|
||||
|
||||
cmd="bundle exec jekyll s"
|
||||
realtime=false
|
||||
|
||||
|
||||
help() {
|
||||
echo "Usage:"
|
||||
echo
|
||||
|
@ -32,23 +35,21 @@ help() {
|
|||
|
||||
|
||||
cleanup() {
|
||||
cd $WORK_DIR
|
||||
rm -rf $CONTAINER
|
||||
rm -rf ${WORK_DIR}/${CONTAINER}
|
||||
ps aux | grep fswatch | awk '{print $2}' | xargs kill -9 > /dev/null 2>&1
|
||||
}
|
||||
|
||||
|
||||
init() {
|
||||
set -eu
|
||||
|
||||
if [[ -d $CONTAINER ]]; then
|
||||
rm -rf $CONTAINER
|
||||
if [[ -d ${WORK_DIR}/${CONTAINER} ]]; then
|
||||
rm -rf ${WORK_DIR}/${CONTAINER}
|
||||
fi
|
||||
|
||||
temp=$(mktemp -d)
|
||||
cp -r * $temp
|
||||
cp -r .git $temp
|
||||
mv $temp $CONTAINER
|
||||
cp -r ${WORK_DIR}/* $temp
|
||||
cp -r ${WORK_DIR}/.git $temp
|
||||
mv $temp ${WORK_DIR}/${CONTAINER}
|
||||
|
||||
trap cleanup INT
|
||||
}
|
||||
|
@ -74,7 +75,7 @@ check_command() {
|
|||
main() {
|
||||
init
|
||||
|
||||
cd $CONTAINER
|
||||
cd ${WORK_DIR}/${CONTAINER}
|
||||
python _scripts/py/init_all.py
|
||||
|
||||
if [[ $realtime = true ]]; then
|
Loading…
Reference in a new issue