Skip to content

Instantly share code, notes, and snippets.

@yoichitgy
Last active July 1, 2022 18:19
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yoichitgy/00357ef560f08a3eb96e to your computer and use it in GitHub Desktop.
Save yoichitgy/00357ef560f08a3eb96e to your computer and use it in GitHub Desktop.
A bash script to deploy GitHub Pages with Hugo.
#!/bin/bash
while getopts p option
do
case $option in
p) opt_p=TRUE ;;
esac
done
if [ ! -d "public" ]
then
echo -e "\033[1;31mDirectory 'public' does not exist. Check whether you are in the hugo root directory.\033[0m"
exit 0
fi
echo -e "\033[0;32mDeploying updates to GitHub...\033[0m"
# Generate the pages.
find public ! -name ".*" -delete
hugo -t angels-ladder
# Go to the submodule directory.
cd public
# Commit changes.
date="`date`"
git add -A
git commit -m "Rebuild the site on $date"
# Push to origin.
git push origin master
# Back to the original directory.
cd ..
# Commit and push the submodule SHA
git add public
git commit -m "Update the submodule SHA on 'public' directory on $date"
git push origin master
# Ping Sitemap
if [ "$opt_p" = TRUE ]
then
curl "http://www.google.com/ping?sitemap=https://yoichitgy.github.io/sitemap.xml"
fi
@aamirafridi
Copy link

Thanks but it doesn't commit changes to the public remove i.e. xxx.github.io branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment