-
-
Save ryanjm/2628759 to your computer and use it in GitHub Desktop.
a hook to deploy static generated sites
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# executables prefix | |
_prefix="/usr/local/bin" | |
# git executable | |
_git="$_prefix/git" | |
# site generation executable | |
_generate="$_prefix/jekyll" | |
# options for the generator | |
_opts=(--no-safe --no-server --no-auto) | |
# branch from which to generate site | |
_origbranch="temp" | |
# branch holding the generated site | |
_destbranch="master" | |
# directory holding the generated site -- should be outside this repo | |
_site="$("/usr/bin/mktemp" -d /tmp/_site.XXXXXXXXX)" | |
# the current branch | |
_currbranch="$($_git branch | /usr/bin/grep "^*" | /usr/bin/cut -d' ' -f2)" | |
if [[ $_currbranch == $_origbranch ]]; then # we should generate the site | |
# go to root dir of the repo | |
cd "$("$_git" rev-parse --show-toplevel)" | |
# generate the site | |
"$_generate" ${_opts[@]} . "$_site" | |
# switch to branch the site will be stored | |
"$_git" checkout "$_destbranch" | |
# overwrite existing files | |
builtin shopt -s dotglob | |
/bin/cp -rf "$_site"/* . | |
builtin shopt -u dotglob | |
# add any new files | |
"$_git" add . | |
# commit all changes with a default message | |
"$_git" commit -a -m "updated site @ $(date +"%F %T")" | |
# cleanup | |
/bin/rm -rfv "$_site" | |
# return | |
"$_git" checkout "$_origbranch" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
chmod u+x .git/hooks/post-commit