Hugo cleaning
Run this to to clean the public folder but make a backup of it first.
Hugo Hosting Settings
- Solution based on submodules
The second submodule-based solution is described in Hugo documentation. At first I could not understand it, but after this video about submodules I worked out how to set up this.
Two repositories:
username-src:
master — source code.
username.github.io:
master — web version (only public folder contents). this repository is added as a submodule to public folder of the username-src repository.
Advantage of this solution — clean history for source code and web version.
Deployment is automated with a script deploy.sh. Setup
Generate a web version of the site in the project folder.
hugo -t hugo-academic # If using other theme edit the command to hugo -t <YOURTHEME>
Initiailze a git repository in public sub-folder and push everything.
cd public
git init
git remote add origin git@github.com:username/username.github.io.git
git add .
git commit -m "initial commit of website"
git push -u origin master
Go to the project folder and totally remove public folder.
cd .. rm -rf public
**Initialize git repository in the project folder. Add public to .gitignore.**
git init
git remote add origin git@github.com:username/username-src.git
echo "public" >> .gitignore
git add .
git commit -m "initial commit of source code"
git push -u origin master
**Connect a repository with web version as a submodule to publicfolder.**
git submodule add -b master git@github.com:varmara/varmara.github.io.git public git add . git commit -m 'added public as a submodule' git push origin master
A script to deploy site
#!/bin/bash
# a script for easy site deploymend from submodule
# make it executable with chmod +x deploy.sh
# Set the English locale for the `date` command.
export LC_TIME=en_US.UTF-8
# The commit message.
MESSAGE="Site rebuild $(date)"
echo -e "\033[0;32mDeploying updates to GitHub...\033[0m"
# Remove old files in public
pushd public
git rm -rf *
popd
# Build the project.
hugo -t hugo-academic # 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 [ $# -eq 1 ]
then MESSAGE="$1"
fi
git commit -m "$MESSAGE"
# Push source and build repos.
git push origin master
# Come Back up to the Project Root
cd ..