my process for creating new Hugo sites
In the past year, I have been creating a number of Hugo sites and modules and have been enjoying the convenience of hosting on Github pages. I routinely run the script command to capture my terminal sessions to later document my processes for future re-use, and if possible, to do so in executable code.
The following is my current such documentation, in bash code, for creating a new Hugo site hosted on Github pages. Obviously, you will need to change the USERNAME variable accordingly.
#!/bin/bash
if [ -z "${1}" ]; then
echo "create a new repository at Github with REPONAME"
echo "then call this script with REPONAME as the first argument"
exit 1
fi
# for convenience, a function similar to Perl's
die() { echo "$*" 1>&2 ; exit 1; }
USERNAME="myusername"
REPONAME="${1}"
[email protected]:"${USERNAME}"/"${REPONAME}".git
hugo new site "${REPONAME}" # creates REPONAME directory
cd "${REPONAME}" || die "no directory named ${REPONAME}"
printf ".envrc\n" > .gitignore
hugo mod init github.com/"${USERNAME}"/"${REPONAME}"
git init
git add *
git commit -m "first commit"
git branch -M main
git remote add origin "${ORIGIN}"
git remote set-url origin "${ORIGIN}"
git push -u origin main
echo "*** REMEMBER to create .envrc as needed to set publish directory at Github"