Skip to content

Instantly share code, notes, and snippets.

@tchartron
Last active December 4, 2020 20:51
Show Gist options
  • Save tchartron/535b7660e2fd555c1b24895a3c7c5091 to your computer and use it in GitHub Desktop.
Save tchartron/535b7660e2fd555c1b24895a3c7c5091 to your computer and use it in GitHub Desktop.
Gohugo deploy to github pages
#!/bin/sh
# If a command fails then the deploy stops
set -e
if [ -d "public" ]
then
printf "\033[0;32mRemoving public folder except .git to keep the submodule...\033[0m\n"
cd public
find . -not -name '.git' -not -name 'README.md' -delete
cd ..
fi
printf "\033[0;32mDeploying updates to GitHub pages...\033[0m\n"
# Build the project.
hugo # if using a theme, replace with `hugo -t <YOURTHEME>`
# Go To Public folder
cd public
# Add changes to git.
git add .
# Commit changes.
msg="rebuilding site $(date)"
if [ -n "$*" ]; then
msg="$*"
fi
git commit -m "$msg"
# Push source and build repos.
git push origin main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment