Skip to content

Instantly share code, notes, and snippets.

@CupOfTea696
Last active August 29, 2015 14:20
Show Gist options
  • Select an option

  • Save CupOfTea696/e347d3e88d8fdd5dca1e to your computer and use it in GitHub Desktop.

Select an option

Save CupOfTea696/e347d3e88d8fdd5dca1e to your computer and use it in GitHub Desktop.
Sync docs with gh-pages branch
#!/bin/bash
## Slightly tweaked version for my personal purposes of https://github.com/CoryG89/docsync/blob/master/post-commit
###
### The following block runs after commit to "master" branch
###
if [ `git rev-parse --abbrev-ref HEAD` == "master" ]; then
# Layout prefix is prepended to each markdown file synced
###################################################################
LAYOUT_PREFIX='---\nlayout: default\n---\n'
# Switch to gh-pages branch to sync it with master
###################################################################
git checkout gh-pages
# Sync the README.md in master to index.md adding jekyll header
###################################################################
git checkout master -- README.md
echo -e $LAYOUT_PREFIX > index.md
cat README.md >> index.md
rm README.md
git add index.md
git commit -a -m "Sync readme from master branch to gh-pages"
# Sync the markdown files in the docs/* directory
###################################################################
git checkout master -- docs
FILES=$(find docs -not -path 'docs/api/*' -name '*.md' -or -not -path 'docs/api/*' -name '*.html')
for file in $FILES
do
echo -e $LAYOUT_PREFIX | cat - "$file" > temp
if [[ ! -d "${file%.*}" ]]; then
mkdir -p "${file%.*}"
fi
mv temp "${file/\.//index.}"
rm $file
done
git add docs
git commit -a -m "Sync docs from master branch to gh-pages"
# Uncomment the following push if you want to auto push to
# the gh-pages branch whenever you commit to master locally.
# This is a little extreme. Use with care!
###################################################################
git push origin gh-pages
# Finally, switch back to the master branch and exit block
git checkout master
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment