Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save snassr/8e5fc274d7df125f54038e27de28a439 to your computer and use it in GitHub Desktop.
Save snassr/8e5fc274d7df125f54038e27de28a439 to your computer and use it in GitHub Desktop.
Medium Blog - Build and Deploy a Hugo Blog With Caddy - Setup Pre-Deployment Environment
# in a new terminal (tab)
# export variables again (unnecessary if in the same terminal session as before)
export GITHUB_USERNAME=snassr
export GITHUB_REPONAME=myblog
export OS_REPOLOCATION=~/$GITHUB_REPONAME
# change directory to blog folder
cd $OS_REPOLOCATION/$GITHUB_REPONAME
# add a caddyfile (setup for display on port 80)
cat << EOF > ./CaddyFile
:80 {
root $OS_REPOLOCATION/$GITHUB_REPONAME/public
}
EOF
# change base url for caddy to serve HTML/CSS/JS correctly
sed -i 's#baseURL = "http://example.org/"#baseURL = "http://localhost/"#g' config.toml
# compile and produce (creates a /public folder with the sites HTML/CSS/JS files)
# run this after every update
hugo
# run caddy
caddy -conf=$OS_REPOLOCATION/$GITHUB_REPONAME/CaddyFile
# visit localhost:80
# commit at this stage (before moving to remote server, will pull from git)
git add --all
git commit -m "Setup Pre-Deployment Environment - completed"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment