summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAssaf Gordon <assafgordon@gmail.com>2016-02-23 03:39:05 (GMT)
committerAssaf Gordon <assafgordon@gmail.com>2016-02-23 03:39:05 (GMT)
commitcc9d0b39084f3e8251d4121c707b98f1a1c550e8 (patch)
tree708d12f78a131822bbf000e094f860171970d9dc
parentd59932fc98b41b7893ff5dea7b93ed5f243bc4f7 (diff)
downloadcode-snippets-cc9d0b39084f3e8251d4121c707b98f1a1c550e8.zip
code-snippets-cc9d0b39084f3e8251d4121c707b98f1a1c550e8.tar.gz
code-snippets-cc9d0b39084f3e8251d4121c707b98f1a1c550e8.tar.bz2
git-post-update-jekyll-hook: new script
-rwxr-xr-xgit-post-update-jekyll-hook65
-rw-r--r--metadata.yml2
2 files changed, 67 insertions, 0 deletions
diff --git a/git-post-update-jekyll-hook b/git-post-update-jekyll-hook
new file mode 100755
index 0000000..ebb5cd9
--- /dev/null
+++ b/git-post-update-jekyll-hook
@@ -0,0 +1,65 @@
+#!/bin/sh
+
+##
+## Post-Update Hook to update Jekyll Website
+## Copyright (C) 2016 Assaf Gordon <assafgordon@gmail.com>
+## License: GPLv2-or-later
+
+## Example of a 'post-update' hook script
+## to trigger a jekyll site rebuild after a push to a git repository.
+## This script should be placed in the git repository's ./hooks/ directory
+## as 'post-update' (and be made executable).
+##
+## After every 'push' to the repository, the script will rebuild
+## the jekyll static web-pages (by default, in ${HOME}/jekyll/www/[PROJECT]).
+## Point your webserver's root directory to this directory and it will
+## serve the website.
+##
+## The BASEDIR directory must be writable by the user running the git push
+## (e.g. gitolite3 user if using gitolite). It must be readable by the
+## web-server user (e.g. www-data on Debian/ubuntu).
+##
+
+## see:
+## http://demonastery.org/2012/11/jekyll-gitolite-hook/
+## http://blog.zerosum.org/2010/11/01/pure-git-deploy-workflow.html
+
+die()
+{
+ BASE=$(basename "$0")
+ echo "$BASE: error: $@" >&2
+ exit 1
+}
+
+# Get project name
+PROJECT=$(basename "$PWD")
+PROJECT=${PROJECT%.git}
+
+BASEDIR=${HOME}/jekyll/
+
+WORKDIR=${BASEDIR}/cache/${PROJECT}
+SITEDIR=${BASEDIR}/www/${PROJECT}
+
+##
+## Directory when the checked out repository is
+##
+mkdir -p "$WORKDIR" "$SITEDIR" \
+ || die "failed to create Jekyll directories"
+
+##
+## Update to the latest version
+##
+git --work-tree=${WORKDIR}/ reset --hard \
+ || die "failed to checkout latest revision on '$WORKDIR'"
+
+# Abort if no Jekyll config found
+test -e "${WORKDIR}/_config.yml" \
+ || die "no Jekyll _config.yml file found. aborting"
+
+##
+## Rebuild
+##
+echo "=== Running Jekyll ==="
+jekyll build --source "$WORKDIR" \
+ --destination "$SITEDIR" \
+ || die "Jekyll failed to build website '$WORKDIR'"
diff --git a/metadata.yml b/metadata.yml
index b4e3e43..08c9ebf 100644
--- a/metadata.yml
+++ b/metadata.yml
@@ -1,6 +1,8 @@
files:
skeleton.sh:
description: 'Shell script skeleton with getops and help screen'
+ git-post-update-jekyll-hook:
+ description: 'Rebuild a jekyll static website on git-push (similar to github pages)'
links:
- name: posix-libc-examples
url: https://git.housegordon.org/gitweb/posix-libc-examples.git