Zola on github Pages
Deploy your Zola generated website to github pages
3 min
504 words
Thomas Chartron
Categories: development
Deploy a zola site to GitHub pages
This will explain how to deploy a website created with Zola SSG to github pages and host it for free.
Requirements
- Github account
- Ready to deploy Zola website (as git repository)
- (Optional) Domain name
Steps
- Create a github reposity with this form :
.github.io and make it public - Create a simple README.md file to describe your project.
- Add this repository which will be used to host the website as a git submodule of your Zola website.
This added the repository we created as a submodule in the public
folder.
- Now go back to the root of the Zola website and copy this script as
deploy.sh
and make it executable
#deploy.sh content
#!/usr/bin/env bash
# If a command fails then the deploy stops
if [
then
fi
# Build the project to another directory because zola will delete the submodule /public otherwise
#Now copy built files to public directory
# Go To Public folder
# Add changes to git.
# Commit changes.
msg="update site content "
if [; then
msg=""
fi
# Push source
- Now deploy your website to https://
.github.io with this simple command : ./deploy.sh "update site content"
. This will remove the previous version of the website locally, then commit all changes
Set up a custom domain name
- Go to your domain name provider DNS zone configuration
- Add A entry pointing to one of github pages IP addresses : 185.199.108.153 list here
- In your github
.github.io repository go to Settings >> Pages >> In Custom Subdomain enter subdomain (example : mydomain.com) - In you DNS zone configuration i recommend adding another entry to use
www.mydomain.com
also. - Add CNAME entry example : www.mydomain.com >>
.github.io. (don't forget final dot for absolute notation)
Troubleshooting
If a submodule was previously added and throws an error like : "A git directory for 'public' is found locally with remote(s)" you can do this
# Delete the relevant lines from the .gitmodules
# Then re add the submodule