uHugo: A CLI Tool for Hugo Static Site Generator
uHugo is a CLI utility tool written in Python for maintaining Hugo binary files. You might think “Wait! don’t we have Homebrew, Chocolatey, Snap and a plethora of other tools for this?” that’s exactly why, and also they are package managers. uHugo takes it to the next step by not only updating your Hugo binary file to the version you need, but also updates cloud provider’s environment variables or configuration files. For example, Cloudflare Pages has a CI/CD system that builds and uploads the files to their storage place, but you will need to specify which version of Hugo you want to used to build these files. Some static host providers have configuration files to specify the version name, whereas Cloudflare Pages don’t; you will need to specify the Hugo version under their environment variable section.
The process of updating environment variables can be automated via a CI/CD provider - GitHub actions, Travis, CircleCI etc. You name it using uHugo ⭐.
Also, did I mention it is cross-platform CLI utility? 🤔
How Should I Install It?
All you need is Python 3.6+ and its package manager - PIP. Open your terminal and type in:
> pip install uhugo
you can confirm the installation by typing:
> uhugo --version
How Should I Use It?
Like any other package manager, it comes with two commands - install
and update
.
Install Command
Installing a fresh Hugo binary is simple as:
> uhugo install
It does some basic steps:
- Checks if Hugo is installed
- Gets the download URL of the latest binary from GitHub
- Downloads to a temporary folder
- Unzips it and move to
<user folder>/bin
, if the folder doesn’t exist, it creates one for you
<p>Note: Make sure you have <code><user folder>/bin</code> in your <code>$PATH</code></p>
There might be a time where you might want to reinstall the binary for this, you can use --force
flag
> uhugo install --force
<p>Note: <code>--force</code> flag will only work when <code><user folder>/bin</code> is in the <code>$PATH</code></p>
Update Command
Updating to the latest version of Hugo is simple as:
> uhugo update
It takes the following steps to make you happy:
- Checks the local Hugo version
- Gets the latest Hugo version and compares it
- If the latest Hugo version is greater than the local Hugo version
- Gets the download URL of the latest binary from GitHub
- Downloads to a temporary folder
- Unzips it and replaces
hugo
binary in<user folder>/bin
Update command can also be used to update any cloud provider’s settings, though this is optional and this uHugo feature is unique from other CLI utilities. To activate this, few steps need to be taken:
- Tell uHugo what providers you want it to check in Hugo’s
config.toml
orconfig.yaml
- Give your project name
- Give an API key, if needed
- Files to check or details regarding the provider
<p>Note: Above steps are only for Cloudflare Pages. For Netlify and Vercel, uHugo searches for <code>netlify.toml</code> and <code>vercel.json</code> respectively.</p>
For example, I deploy my website on Cloudflare, so let’s take an example of it. In my config.toml
, I have the following settings:
[uhugo]
name = "cloudflare"
project = "gollahalli-com"
email_address = "env:email-address"
account_id = "env:account-id"
api_key = "env:api-key"
env:email-account
is a special name in uHugo, this tells uHugo to replace the value email-account
from the environment variable and use that value instead.
Whenever uHugo detects these configurations, it updates the value for HUGO_VERSION
in production and preview environment variables.
Support for Cloud Providers
uHugo currently supports following cloud providers:
- Cloudflare - API based
- Netlify - File based, looks for
netlify.toml
- Vercel - File based, looks for
vercel.json
Final Thoughts
uHugo was purely built out of frustration for downloading the latest binary file and changing the variable names on Cloudflare (login
> use the correct account
> Pages
> select projects
> settings tabs
> environment variables tab
> edit variables for production and preview
> don't forget to save it
😫), Netlify (update the Hugo version in the config file) and Vercel.
I hope this CLI utility helps you in making your deployment a bit more productive.
Happy coding :nerd: