Automating Nikola rebuilds with GitHub Actions

In this guide, we’ll set up GitHub Actions to rebuild a Nikola website and host it on GitHub Pages.

Why?

By using GitHub Actions to build your site, you can easily blog from anywhere you can edit text files. Which means you can blog with only a web browser and GitHub.com. You also won’t need to install Nikola and Python to write. You won’t need a real computer either — a mobile phone could probably access GitHub.com and write something.

Caveats

  • The build might take a couple minutes to finish (1:30 for the demo site; YMMV)

  • When you commit and push to GitHub, the site will be published unconditionally. If you don’t have a copy of Nikola for local use, there is no way to preview your site.

What you need

  • A computer for the initial setup that can run Nikola. You can do it with any OS (Linux, macOS, *BSD, but also Windows).

  • A GitHub account (free)

Setting up Nikola

Start by creating a new Nikola site and customizing it to your liking. Follow the Getting Started guide. You might also want to add support for other input formats, namely Markdown, but this is not a requirement.

After you’re done, you must configure deploying to GitHub in Nikola. There are a few important things you need to take care of:

  • Make your first deployment from your local computer and make sure your site works right. Don’t forget to set up .gitignore.

  • The GITHUB_COMMIT_SOURCE and GITHUB_REMOTE_NAME settings are overridden, so you can use values appropriate for your local builds.

  • Ensure that the correct branch for GitHub Pages is set on GitHub.com.

If everything works, you can make some change to your site (so you see that rebuilding works), but don’t commit it just yet.

Setting up GitHub Actions

Next, we need to set up GitHub Actions. This is really straightforward.

On your source branch, create a file named .github/workflows/main.yml with the following contents:

github-workflow.yml (Source)

on: [push]
jobs:
  nikola_build:
    runs-on: ubuntu-latest
    name: 'Deploy Nikola to GitHub Pages'
    steps:
    - name: Check out
      uses: actions/checkout@v2
    - name: Build and Deploy Nikola
      uses: getnikola/nikola-action@v2

There might be a newer version of the action available, you can check the latest version in the getnikola/nikola-action repo on GitHub.

By default, the action will install the latest stable release of Nikola[extras]. If you want to use the bleeding-edge version from master, or want to install some extra dependencies, you can provide a requirements.txt file in the repository.

Commit everything to GitHub:

git add .
git commit -am "Automate builds with GitHub Actions"

Hopefully, GitHub will build your site and deploy. Check the Actions tab in your repository or your e-mail for build details. If there are any errors, make sure you followed this guide to the letter.

Nikola v8.0.4 is out!

On behalf of the Nikola team, I am pleased to announce the immediate availability of Nikola v8.0.4. This release fixes a few small bugs, including a date glitch that appeared around New Year’s Eve.

What is Nikola?

Nikola is a static site and blog generator, written in Python. It can use Mako and Jinja2 templates, and input in many popular markup formats, such as reStructuredText and Markdown — and can even turn Jupyter Notebooks into blog posts! It also supports image galleries, and is multilingual. Nikola is flexible, and page builds are extremely fast, courtesy of doit (which is rebuilding only what has been changed).

Find out more at the website: https://getnikola.com/

Downloads

Install using pip install Nikola.

Changes

Nikola now supports Python 3.5 or newer. If you are on 3.4, please upgrade to a newer release of Python.

Bugfixes

  • Fix hiding future posts in sitemaps for posts without pretty URLs (Issue #3339)

  • Pass the correct parameters to shortcodes in jupyter notebooks

  • Fix handling of conflicts between posts/pages and indexes generated by CATEGORY_PAGES_FOLLOW_DESTPATH

  • Fix default date format to yyyy-MM-dd to avoid bug with ISO years (Issue #3337)

  • Remove extra_header and extra_footer from base theme due to incompatibility with Mako. The blocks are still available in bootstrap4 and bootblog4. (Issue #3319 via #3291)

  • Show tracebacks when conf.py cannot be imported

  • Fix loading complex config files that import modules (Issue #3314)

  • Fix behavior of header demotion for negative values

  • If FILE_METADATA_REGEXP is set, load metadata from the filename first, then continue with the other sources (Issue #3344)

Nikola v8.0.3 is out!

On behalf of the Nikola team, I am pleased to announce the immediate availability of Nikola v8.0.3. This release fixes a few bugs, including a notable one with galleries not working on mobile.

What is Nikola?

Nikola is a static site and blog generator, written in Python. It can use Mako and Jinja2 templates, and input in many popular markup formats, such as reStructuredText and Markdown — and can even turn Jupyter Notebooks into blog posts! It also supports image galleries, and is multilingual. Nikola is flexible, and page builds are extremely fast, courtesy of doit (which is rebuilding only what has been changed).

Find out more at the website: https://getnikola.com/

Downloads

Install using pip install Nikola.

Changes

Features

  • Add Friulian translation by aoanla

  • Add extra_header and extra_footer blocks to templates (Issue #3291)

  • Add REST_FILE_INSERTION_ENABLED config option to enable or disable reST external file inclusion directives (Issue #3311)

Bugfixes

  • Support Markdown v3.x (Issue #3173)

  • Fix galleries in Firefox Mobile and when resizing window (Issue #3258)

  • Output <code> tag for double backticks in reST (Issue #3276)

  • Fully switch to HTML5 writer for reST (Issue #3276, getnikola/plugins#294)

  • Make ipynb listings work again

  • Correctly link to listings with spaces in their names

  • import_wordpress plugin doesn't require anymore a translation and can use nikola's default if none provided

  • Wordpress+qtranslate import (--qtranslate option) now works with more recent versions of plugins from the qtranslate family (namely qtranslate-X)

  • Fixed a wordpress import exception when image metadata has floats formated with ',' instead of '.'

Nikola v8.0.2 is out!

On behalf of the Nikola team, I am pleased to announce the immediate availability of Nikola v8.0.2. This is a quality-of-life release with a handful of bug fixes, two new translations and a few extra features.

What is Nikola?

Nikola is a static site and blog generator, written in Python. It can use Mako and Jinja2 templates, and input in many popular markup formats, such as reStructuredText and Markdown — and can even turn Jupyter Notebooks into blog posts! It also supports image galleries, and is multilingual. Nikola is flexible, and page builds are extremely fast, courtesy of doit (which is rebuilding only what has been changed).

Find out more at the website: https://getnikola.com/

Downloads

Install using pip install Nikola. (Python 3-only since v8.0.0.)

Changes

  • Make ARCHIVE_PATH, ARCHIVE_FILENAME translatable (Issue #3234)

  • Support configuring Isso via GLOBAL_CONTEXT['isso_config'] (Issue #3225)

  • Handle fragments in doc role (Issue #3212)

  • Slugify references in doc role.

  • Add Interlingua translation by Alberto Mardegan

  • Add Afrikaans translation by Friedel Wolff

  • Support for docutils.conf (Issue #3188)

Bugfixes

  • Avoid random rebuilds with sites whose locales are not fullly supported, and random rebuilds on multilingual sites using Python 3.4/3.5 (Issue #3216)

  • Apply modifications to default_metadata before copying it to other languages

  • Make Commento comments work (Issue #3198)

  • Correctly handle separators in the relative path given to "ignored_assets" key in theme meta files (Issue #3210)

  • Fix error when nikola new_post receives directory name as path (Issue #3207)

  • Add slashes to paths with query strings in nikola serve only if there isn’t one before ?

  • Read listings files as UTF-8

  • Set one-file status basing on default language only (Issue #3191)

  • Don’t warn if post status is set to published explicitly (Issue #3181)

  • Remove mention of Twitter cards requiring an opt-in. This is not true anymore - anyone can use them.

  • fancydates now workwith listdate items (eg. archives)

  • bootstrap4 and bootblog4 themes no longer load moment.js when fancydates are off. (Issue #3231)