It is an annoying thing that I cannot add custom plugins if GitHub pages runs Jekyll for me.

Thus, I need to build the site myself and let GitHub pages to present my built site.

Note that GitHub pages serving personal users cannot present the site deployed in docs dir of master branch or in root of gh-pages branch, so I need to put my Jekyll source in the development branch, and push the built site to the master branch when I think it is ready to be published.

I have written a script to do it for me:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
MESSAGE=$1

echo "Committing..."
git commit -m "$MESSAGE" --author "$AUTHOR"

echo "Backing up..."
mv _site/.git git_backup

echo "Building..."
jekyll build --quiet

echo "Restoring..."
mv git_backup/.git _site
cd _site

echo "Pushing..."
git add -- **/*
git commit -m "$MESSAGE" --author "$AUTHOR"
git push --set-upstream origin master

where AUTHOR is your name and email in the format name <email>.

Before that, I need to initialize the _site dir as a git repo:

1
2
3
4
5
6
cd site_
git init
git remote add origin $REMOTE_URL
git add -f -- **/*
git commit -m "initial commit"
git push -f --set-upstream origin master

where REMOTE_URL is the GitHub url of the repo of your site.