Last active
December 8, 2019 16:38
-
-
Save gmolveau/860c0200f96f0cb4fb64243d1dcc943d to your computer and use it in GitHub Desktop.
GoHugo publish on gh-pages/docs branch for Github Pages
This file contains hidden or 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 sh | |
REMOTE="origin" | |
BRANCH="gh-pages" | |
HUGO_FOLDER="public" | |
if ! git diff-files --quiet --ignore-submodules -- | |
then | |
echo "The working directory is dirty. Please commit any pending changes." | |
exit 1; | |
fi | |
echo "Switching to master branch" | |
echo "If you're using git flow, please make sure master branch is up to date." | |
git checkout master | |
echo "Deleting old publication" | |
rm -rf ${HUGO_FOLDER} | |
mkdir ${HUGO_FOLDER} | |
git worktree prune | |
echo "Checking out ${BRANCH} branch into {HUGO_FOLDER}" | |
git worktree add -B ${BRANCH} {HUGO_FOLDER} --no-checkout | |
echo "Generating site" | |
hugo | |
echo "Writing CNAME file" | |
if [ ! -f ./CNAME ]; then | |
read -p "Enter the production URL (e.g. myblog.idontknow.com): " PRODUCTION_URL | |
echo "${PRODUCTION_URL}" > {HUGO_FOLDER}/CNAME | |
else | |
cat CNAME > {HUGO_FOLDER}/CNAME | |
fi | |
echo "Updating ${BRANCH} branch" | |
cd {HUGO_FOLDER} && git add --all && git commit -m "Publishing (publish.sh)" && cd .. | |
echo "Pushing to github" | |
git push ${REMOTE} +${BRANCH} | |
echo "Finished, cleaning up" | |
rm -rf {HUGO_FOLDER} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment