Deploy Hexo to Cloudflare Pages

Alternative to Netlify/GitHub/GitLab Pages

Cloudflare Pages was initially announced back in mid-December 2020. Since I’m already using its CDN on mdleom.com, it’s a no-brainer to me to adopt it. At first glance, this may result in better performance than my previous setup which puts Cloudflare CDN in front of Netlify. So, I went straight for the beta sign up.

The sign up email said that I will be notified when it’s ready for testing. Today I noticed it’s available on my dashboard, despite never receive the notification.

Cloudflare Pages Dash

The installation was straightforward, I just need to install Cloudflare Pages app on my GitHub account. Currently, it only supports GitHub, fortunately I have a GitHub mirror of my primary blog repo on GitLab.

Once the app is installed, I granted access to the blog repo. After that, it redirected back to the Cloudflare to continue setup. The next step is to specify the repo again. Then, I specified a unique project name, this has to be unique among all Cloudflare Pages; in this case, I use “curben” so it’s hosted at curben.pages.dev. I selected “Hexo” from the framework preset selections, this resulted in hexo generate build command and public output directory. Alternatively, you could also specify npm run build command if you install Hexo after 4 Oct 2019; this convention is similar to Svelte and Vue.

Clouflare Pages build settings

Once configured, I just need to wait for the blog to be built and deployed. My blog is deployed to curben.pages.dev and 6c9d9856.curben.pages.dev, the later is a snapshot of the build at that time.

Every push to the git repo will trigger a new build and subsequently a new snapshot; in my case, curben.pages.dev always points to the latest snapshot. Having a snapshot means I can easily revert to previous one without having to revert git commits, though it’s not available yet. This feature is not new, it was one of the earliest features of Netlify that differentiate itself from other static site hosting.

Cloudflare Pages build progress

Speaking of Netlify, I haven’t replace it with Clouflare Pages and currently not planning to. Instead, I deploy my blog (including .onion and Eepsite) to two identical web servers that can failover to the following mirrors:

  1. curben.pages.dev
  2. curben.netlify.app
  3. curben.gitlab.io
  4. curbengh.github.io