From d4ad62951457ce196a6ac2194ff1b9738caafbf8 Mon Sep 17 00:00:00 2001 From: Ivan Malison Date: Wed, 19 Oct 2016 17:57:03 -0700 Subject: [PATCH] [Emacs] Add github pages publishing hooks --- dotfiles/emacs.d/bin/git-hooks/post-commit | 9 +++++++++ dotfiles/emacs.d/bin/install_hooks.sh | 20 ++++++++++++++++++++ dotfiles/emacs.d/bin/update_github_page.sh | 6 ++++++ dotfiles/emacs.d/bin/util.sh | 20 ++++++++++++++++++++ 4 files changed, 55 insertions(+) create mode 100755 dotfiles/emacs.d/bin/git-hooks/post-commit create mode 100755 dotfiles/emacs.d/bin/install_hooks.sh create mode 100755 dotfiles/emacs.d/bin/update_github_page.sh create mode 100755 dotfiles/emacs.d/bin/util.sh diff --git a/dotfiles/emacs.d/bin/git-hooks/post-commit b/dotfiles/emacs.d/bin/git-hooks/post-commit new file mode 100755 index 00000000..f1a25f09 --- /dev/null +++ b/dotfiles/emacs.d/bin/git-hooks/post-commit @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +THIS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +source "$THIS_DIR/../util.sh" + +if readme_was_updated; then + update_index + commit_index_changes +fi diff --git a/dotfiles/emacs.d/bin/install_hooks.sh b/dotfiles/emacs.d/bin/install_hooks.sh new file mode 100755 index 00000000..838bec59 --- /dev/null +++ b/dotfiles/emacs.d/bin/install_hooks.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +TOP_LEVEL="$(git rev-parse --show-toplevel)" +HOOK_DIR="$TOP_LEVEL/.git/hooks" + +THIS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +SOURCE_DIR="$THIS_DIR/git-hooks" + +for hook in "$SOURCE_DIR"/*; do + filename=$(basename "$hook") + source="$SOURCE_DIR/$filename" + dest="$HOOK_DIR/$filename" + # If the hook already exists, is executable, and is not a symlink + if [ -e "$dest" ]; then + mv "$dest" "$dest.local" + fi + echo "linking $source to $dest" + ln -s "$source" "$dest" + chmod 755 "$dest" +done diff --git a/dotfiles/emacs.d/bin/update_github_page.sh b/dotfiles/emacs.d/bin/update_github_page.sh new file mode 100755 index 00000000..3a9904a0 --- /dev/null +++ b/dotfiles/emacs.d/bin/update_github_page.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +THIS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +source "$THIS_DIR/util.sh" + +update_index diff --git a/dotfiles/emacs.d/bin/util.sh b/dotfiles/emacs.d/bin/util.sh new file mode 100755 index 00000000..e69b0ebc --- /dev/null +++ b/dotfiles/emacs.d/bin/util.sh @@ -0,0 +1,20 @@ +# -*- mode: sh -*- +EMACS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )" +TOP_LEVEL="$(git rev-parse --show-toplevel)" +README="$EMACS_DIR/README.org" +REPOSITORY_NAME="$(realpath --relative-to="$TOP_LEVEL" "$README")" + +readme_was_updated() { + git diff HEAD~1 --name-only | grep --quiet "$REPOSITORY_NAME" +} + +update_index () { + emacsclient -e "(with-current-buffer (find-file-noselect \"$README\") + (org-html-export-to-html))" + cp -f "$EMACS_DIR/README.html" "$TOP_LEVEL/index.html" +} + +commit_index_changes () { + git add "$TOP_LEVEL/index.html" + git commit -m "[Emacs] Update github pages index file" +}