Skip to content

Zola

Zola ↗︎ is a fast static site generator in a single binary with everything built-in. In this guide, you will create a new Zola application and deploy it using Cloudflare Pages. You will use the zola CLI to create a new Zola site.

Installing Zola

First, install ↗︎ the zola CLI, using the specific instructions for your operating system below:

macOS (Homebrew)

If you use the package manager Homebrew ↗︎, run the brew install command in your terminal to install Zola:

brew install zola

Windows (Chocolatey)

If you use the package manager Chocolatey ↗︎, run the choco install command in your terminal to install Zola:

choco install zola

Windows (Scoop)

If you use the package manager Scoop ↗︎, run the scoop install command in your terminal to install Zola:

scoop install zola

Linux (pkg)

Your Linux distro's package manager may include Zola. If this is the case, you can install it directly using your distro's package manager -- for example, using pkg, run the following command in your terminal:

pkg install zola

If your package manager does not include Zola or you would like to download a release directly, refer to the Manual section below.

Manual installation

The Zola GitHub repository contains pre-built versions of the Zola command-line tool for various operating systems, which can be found on the Releases page ↗︎.

For more instruction on installing these releases, refer to Zola's install guide ↗︎.

Creating a new project

With Zola installed, create a new project by running the zola init command in your terminal using the default template:

zola init my-zola-project

Upon running zola init, you will be prompted with four questions:

  1. What is the URL of your site? (https://example.com): You can leave this one blank for now.
  2. Do you want to enable Sass compilation? [Y/n]: Y
  3. Do you want to enable syntax highlighting? [y/N]: y
  4. Do you want to build a search index of the content? [y/N]: y

Before you continue

This guide assumes you already have a fundamental understanding of Git ↗︎. If you are new to Git, refer to the GitHub guide to Git ↗︎ on how to set up Git on your local machine.

If you clone with SSH, you must generate SSH keys ↗︎ on each computer you use to push or pull from GitHub.

Refer to the GitHub documentation ↗︎ and Git documentation ↗︎ for more information.

Create a GitHub repository

Create a new GitHub repository by visiting repo.new ↗︎. After creating a new repository, go to your newly created project directory to prepare and push your local application to GitHub by running the following commands in your terminal:

git remote add origin https://github.com/<your-gh-username>/<repository-name>
git branch -M main
git push -u origin main

Deploy with Cloudflare Pages

To deploy your site to Pages:

  1. In the Cloudflare dashboard, go to the Workers & Pages page.

    Go to Workers & Pages ↗
  2. Select Create application (if prompted).

  3. At the bottom of the page, select the link to continue to Cloudflare Pages (Get started or Continue to Pages).

  4. Select Import an existing Git repository.

  5. Select the new GitHub repository that you created and then select Begin setup.

  6. In the Build settings section, select Zola as your Framework preset. Your selection will provide the following information:

Configuration optionValue
Production branchmain
Build commandzola build
Build directorypublic

Zola is preinstalled in the Cloudflare Pages build environment, so no additional configuration is required. You can optionally set the ZOLA_VERSION environment variable under Environment variables (or Settings > Variables and Secrets) to pin a specific version.

For example, ZOLA_VERSION: 0.22.1.

After configuring your site, you can begin your first deploy. You should see Cloudflare Pages building your site with Zola before deploying it.

After deploying your site, you will receive a unique subdomain for your project on *.pages.dev.

You can now add that subdomain as the base_url in your config.toml file.

For example:

# The URL the site will be built for
base_url = "https://my-zola-project.pages.dev"

Every time you commit new code to your Zola site, Cloudflare Pages will automatically rebuild your project and deploy it. You will also get access to preview deployments on new pull requests, so you can preview how changes look to your site before deploying them to production.

Handling preview deployments

When working with Cloudflare Pages, you might use preview deployments for testing changes before merging to your main branch. However, these preview deployments use different URLs (like https://your-branch-name.my-zola-project.pages.dev), which can cause issues with asset loading if your base_url is hardcoded.

To fix this, modify your build command in the Cloudflare Pages configuration to dynamically set the base URL depending on the environment:

if [ "$CF_PAGES_BRANCH" = "main" ]; then zola build; else zola build --base-url $CF_PAGES_URL; fi

This command uses:

  • The base_url set in config.toml when building from the main branch
  • The preview deployment URL (automatically provided by Cloudflare Pages as $CF_PAGES_URL) for all other branches

Learn more

By completing this guide, you have deployed your Zola site to Cloudflare Pages. For new projects, refer to Cloudflare Workers framework guides, or refer to the Pages framework guides for other Pages setups.

Was this helpful?