How to Deploy a Nikola Static Site on Cloudflare Pages: A Step-by-Step Guide
Tags: cloudflarepages, nikola, staticsitedeployment, technical
Published: 2023-12-09 00:38:20

---
title: How to Deploy a Nikola Static Site on Cloudflare Pages: A Step-by-Step Guide
published: true
date: 2023-12-07 08:00:00 UTC
tags: cloudflarepages,nikola,staticsitedeployment,technical
canonical_url: https://diegocarrasco.com/deploy-nikola-site-cloudflare-pages/
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/22fqj5x3u7s2t2ip2bpp.jpg
---

Table of Contents

- [Context: Nikola Static Site Generator](https://diegocarrasco.com/deploy-nikola-site-cloudflare-pages/#_context_nikola_static_site_generator)
- [Why Cloudflare Pages?](https://diegocarrasco.com/deploy-nikola-site-cloudflare-pages/#_why_cloudflare_pages)
- [What are Deploy Hooks? → Automatic scheduled posts in static sites!](https://diegocarrasco.com/deploy-nikola-site-cloudflare-pages/#_what_are_deploy_hooks_automatic_scheduled_posts_in_static_sites)
- [Step-by-Step Guide to Deploying on Cloudflare Pages](https://diegocarrasco.com/deploy-nikola-site-cloudflare-pages/#_step_by_step_guide_to_deploying_on_cloudflare_pages)
  - [Step 1: Setting Up Your Environment](https://diegocarrasco.com/deploy-nikola-site-cloudflare-pages/#_step_1_setting_up_your_environment)
    - [Sample Pipfile](https://diegocarrasco.com/deploy-nikola-site-cloudflare-pages/#_sample_pipfile)
    - [Configuring Asciidoc in Nikola (optional)](https://diegocarrasco.com/deploy-nikola-site-cloudflare-pages/#_configuring_asciidoc_in_nikola_optional)
  - [Step 2: Link Your Repository](https://diegocarrasco.com/deploy-nikola-site-cloudflare-pages/#_step_2_link_your_repository)
- [References](https://diegocarrasco.com/deploy-nikola-site-cloudflare-pages/#_references)

<!-- toc disabled -->

## Context: Nikola Static Site Generator

Static websites have become increasingly popular in the web development world for their speed, security, and simplicity. [Nikola](https://getnikola.com), a widely-used Python-based static site generator, facilitates the creation of content-rich yet lightweight websites.

You can use many markup-languages allowing you to choose the ones you like the most. You can even write some articles in Markdown, some in Asciidoc, some in reST and some in HTML, and Nikola will process them accordingly.

There are many other SSGs (Static Site Generators) out there, like [Jekyll](https://jekyllrb.com/), [Hugo](https://gohugo.io/), [Eleventy](https://www.11ty.dev/), [Gatsby](https://www.gatsbyjs.com/), [Hexo](https://hexo.io/), [MkDocs](https://www.mkdocs.org/), [Pelican](https://www.pelicanblog.org/), [Zola](https://www.zola.dev/), and many more. I’ve tried many of them (at list all them in the list above,) and I’ve found Nikola to be the best **_for my needs_**.

Your needs might be different, so I encourage you to try them all and choose the one that fits you the best. If in doubt, I recommend you to start with Nikola.

If you write all your content in Markdown, you can write a couple of articles and try each framework out there. The only thing you may have to change is the metadata format.

Anyway, **this article is not about Nikola, but about how to deploy a Nikola site on Cloudflare Pages**. and **the steps described here can be applied to any other SSG** , as long as you use the correct file for their dependency manager.

There is a list of supported SSGs (Frameworks) in the [Cloudflare Pages documentation](https://developers.cloudflare.com/pages/framework-guides/).

Hosting options like [GitHub Pages](https://pages.github.com/), [GitLab Pages](https://docs.gitlab.com/ee/user/project/pages/), and [Cloudflare Pages](https://pages.cloudflare.com/) provide free, reliable and fast platforms for these kind of sites.

## Why Cloudflare Pages?

**Cloudflare Pages** stands out, in my opinion, for:

- its performance optimization and enhanced security (includes a basic WAF - Web Application Firewall - and DDoS protection),

- its integration with their awesome DNS management,

- integrated analytics (although with data for the last 30 days only),

- its integration with Cloudflare CDN and proxy,

- its free subdomain under `pages.dev` (if you need one),

- its free SSL certificate,

- its multi-branch deployments (meaning you can deploy different branches to different subdomains and check if everything looks like you want before merging to master. You can also always re-deploy an old commit), and

- its support for custom domains,

making it an excellent choice for hosting Nikola sites (or any kind of static sites, actually).

But the main reason I chose Cloudflare Pages is that it has **Deploy hooks**!

## What are Deploy Hooks? → Automatic scheduled posts in static sites!

Deploy hooks are URLs that you can use to trigger a new deployment of your site. This is useful when you want to automate the deployment of your site, for example, when you push a new commit to your repository, or when you use Nikola to schedule posts in the future.

With deploy hooks I can set up a Zap in Zapier or a Flow in ActivePieces to trigger a rebuild of my site (event when there is no new commits to the repo) and, because of the date Nikola will publish automatically the new scheduled post.

**Yes, I can have dynamism in my static site!**

This means:

1. I can schedule posts in the future (meaning I can write 4 articles in a week and publish them once a week at the right time. This is good for me because I often write in batches or spurts of energy, interests and time).

2. I can have a Zap (in Zapier) or a Flow (in ActionPieces) that will trigger a rebuild of my site every day at 10:00, so I can have a new post published every day at 10:00 (or 10:05, depending on the speed of the rebuild).

_I will get into more detail about this in a future post._

## Step-by-Step Guide to Deploying on Cloudflare Pages

### Step 1: Setting Up Your Environment

A `Pipfile` is essential for deploying on Cloudflare Pages, as it manages your Python dependencies.

This file’s contents will depend on the specific configurations and input formats of your Nikola site, such as Markdown, Asciidoc, or reST.

The `Pipfile` is used by the [Pipenv](https://pipenv.pypa.io/en/latest/) tool, which is used to manage Python dependencies and virtual environments.

| | In this article I write also about a Gemfile, which is used by the [Bundler](https://bundler.io/) tool, which is used to manage Ruby dependencies and virtual environments. I added this because I use asciidoctor (Ruby-based) to process my Asciidoc files. |

| | **Both files (Pipfile and Gemfile) have to be in the root of your repository.** |

#### Sample Pipfile

This sample `Pipfile` includes the dependencies for a Nikola site using Markdown and Asciidoc. You may update the versions as needed.

```
[[source]]
url = 'https://pypi.python.org/simple'
verify_ssl = true
name = 'pypi'

[requires]
python_version = '3.7'

[packages]
Nikola = '8.2.2'
markdown = '3.3'
asciidoc = '10.2.0'
pygments = '2.13.0'
jinja2 = '3.1.2'
```

#### Configuring Asciidoc in Nikola (optional)

Configuring Asciidoc in Nikola involves specifying the binary path and options in the `conf.py` file.

In this case I want to use asciidoctor as the binary and I want to have a table of contents and use Font Awesome icons when processing the file.

```
ASCIIDOC_BINARY = "asciidoctor"

# Specify options to the asciidoc compiler (as a string).
ASCIIDOC_OPTIONS = "-a toc -a icons=font -a icon-set=fa"
```

##### Sample Gemfile

For Nikola sites using Asciidoc, a `Gemfile` is also required to ensure proper processing of Asciidoc files.

```
source 'https://rubygems.org'
gem 'asciidoctor'
```

### Step 2: Link Your Repository

1. Sign in to Cloudflare Pages.

2. Choose 'Workers and Pages' from the left sidebar.

3. Click the tab 'Pages'.

4. Clock "Connect to Git" to connect your GitHub or GitLab account.

5. Select the repository containing your Nikola site.

6. Configure the build settings as per your project’s needs.

* * *

And that’s it!

Happy deploying!

## References

- [Nikola documentation](https://getnikola.com/documentation.html)

- [Cloudflare Pages docs](https://developers.cloudflare.com/pages/)