How to Deploy a Cryogen Blog to Netlify
Cryogen is a static site generator written in Clojure while Netlify is a slick and powerful platform for deploying static websites. Can they play well together? Yes!
The Cryogen website describes how to deploy to Github Pages, which works fine, but personally I found it easier to deploy my site to Netlify. In terms of price, they’re both free. Netlify has a free tier which is more than sufficient for hobby or personal projects.
So, if you’d like to have a go deploying your Cryogen blog to Netlify, here’s how.
Step 1: Build your website locally
- Edit config.edn in your Cryogen project and set
:blog-prefix
to""
. This prefix will be prepended to all URIs. We want it blank because otherwise it will confuse Netlify. - Build your site with
lein run
.
Step 2: Deploy using the Netlify Web Interface
We’ll do our first deploy with the web interface because it’s so quick and easy.
- Create a free account at https://netlify.com
- Drag the whole
public
folder of your site into the area in Netlify labelled “Want to deploy a new site without connecting to Git? Drag and drop your site folder here”. - That’s it. Seriously.
- When you want to update your site, navigate the to site’s project in Netlify, go to the “deploys” tab, and drag the new version of your site onto the region that says “Need to update your site? Drag and drop your site folder here”.
While you’re on the Netlify website you might want to change the domain settings for your site. By default you get a random name, so go ahead and change it to something that’s meaningful to you.
The Netlify web interface is all well and good, but it would be quicker to do subsequent deployments from the command line, so let’s set that up.
Step 3: Deploy using the Netlify CLI
This section assumes that you’ve already done your first deploy with the web interface.
- Follow these
instructions to install netlify CLI on your local machine. Essentially, you just run two commands:
npm install netlify-cli -g
netlify login
- Run
netlify deploy --dir=public
- Select “link this directory to an existing site”, since you’ve already created your site with the web interface.
- Select “Choose from a list of your recently updated sites”
- Select the site from the list
- You’ll be given a live draft url. Open the url and check that your site looks correct.
- If it looks good and you want to deploy to production, then run
netlify deploy --dir=public --prod
. This is also the command you can use for all subsequent deploys. - If you mess up, e.g. by accidentally linking your project to the wrong Netlify site, then just run
netlify unlink
, and then next time you runnetlify deploy
you’ll have the option to set things up from the start again.
If you’re on a Mac, you can streamline things even more by creating a file called deploy.command in your project’s directory with the following contents
#!/bin/bash
# Change to the directory from which the script is being run
cd "$(dirname "$BASH_SOURCE")" || {
echo "Error getting script directory" >&2
exit 1
}
lein do clean, run &&\
netlify deploy --dir=public --prod
Once you’ve made the file run chmod +x deploy.command
. Now you can build and deploy your site just by double-clicking on the deploy.command file in Finder.
Update: Changed my mind and used Hugo
The irony of this post is that since writing it a few days ago I’ve already migrated my (fledgling) blog from Cryogen to Hugo. I really liked Cryogen and in some ways the usability of the blog it generated was superior to this Hugo-generated one. However, I wanted something with a polished look and feel and the Hugo Academic theme offered that out of the box.
I’m still going to leave this post up in case it helps other folks out there who want an easy way to deploy a Cryogen blog!