
If you are reading this, then you are looking at the result of a migration that kept me busy for a good part of October. Alien Pastures is no longer a WordPress blog. After eighteen years of WordPress (the first post on this blog dates from 2008), every page you see here is a plain HTML file, generated from text files in a git repository, and served by Apache without a single line of PHP or a database query in sight.
Why? I was getting tired of patching WordPress and its plugins, of the never-ending stream of login attempts and spam comments, of keeping PHP and MariaDB happy, and of the nagging feeling that the most exposed service on my server was also the one with the largest attack surface. Already some years ago I had done a quick research on Hugo, a framework for building static websites. A blog does not need to be a dynamic web application. It needs to show text and pictures, let people comment, and let me write new articles in a comfortable way.
That last part is where most “static site” tutorials stopped being helpful. They assume that you love editing Markdown files in vi and running build commands by hand. I do love vi, but I also want to write a blog post from a browser on my laptop, drop in a screenshot, and press “Publish”. And then, what do do with reader comments on a blog with static pages? I want my readers to be able to leave comments, without me handing their data to Disqus or another Big Tech service.
So I built a complete blogging platform out of Open Source components, all running on my own servers. It turned out to be a perfect fit for the Slackware Cloud Server series, because it combines several things we already did in earlier episodes (Docker, Apache reverse proxies, Let’s Encrypt) with some new ones: a git forge with CI/CD, a package registry, and a “pull” deployment that does not need any SSH keys.
Check out the list below which shows past, present and future episodes in my Slackware Cloud Server series. If the article has already been written you’ll be able to click on the subject. The first episode also contains an introduction with some more detail about what you can expect.
- Episode 1: Managing your Docker Infrastructure
- Episode 2: Identity and Access management (IAM)
- Episode 3: Video Conferencing
- Episode 4: Productivity Platform
- Episode 5: Collaborative document editing
- Episode 6: Etherpad with Whiteboard
- Episode 7: Decentralized Social Media
- Episode 8: Media Streaming Platform
- Episode 9: Cloudsync for 2FA Authenticator
- Episode 10: Workflow Management
- Episode 11: Jukebox Audio Streaming
- Episode 12: Local AI
- Episode 13 (this article): Blogging Platform
Setting up a static blog with Hugo, built automatically by a Forgejo runner, with Pagefind search, Artalk comments that you moderate yourself, and the Sveltia CMS editor in your browser. No database, no PHP, no SSH keys on your web server.
- Why would I want a static blog?
- What happens where?
- Preamble
- Web hosts
- What you should already have
- Port numbers
- Secret keys
- File locations
- Server configuration steps
- A Hugo site in a git repository
- The builder image
- Prepare the forge
- The build workflow
- The web server pulls the site
- Comments with Artalk
- Moderation, the WordPress way
- Writing posts in your browser with Sveltia CMS
- Announcing new posts on Mastodon
- Check the result
- Coming from WordPress?
- Lessons learned
- Attribution
- Final thoughts
- Episode X: Git Forge
- Episode X: Bot Protection with Anubis
- Episode X: Server Monitoring
- Episode X: Docker Registry
Why would I want a static blog?
A “static” website consists of files that are created once, and then served to every visitor as they are. Compare that to WordPress, where every page view runs PHP code which queries a database and assembles the page on the spot. Let me list the advantages of going static:
- Security
There is nothing to hack on the web server. No login page, no PHP, no plugins with yet another vulnerability, no database with your users’ password hashes. The web server only hands out files. My server logs are still full of bots trying
/wp-login.php, but now they get a polite “410 Gone” and that’s it. - Speed A static page is as fast as your web server can read a file from disk. No caching plugins needed.
- Low maintenance No more monthly WordPress core updates, plugin updates, theme updates, PHP upgrades that break a plugin, database upgrades… Apache and the Artalk comment server are the only things to keep up to date.
- My content is just text
Every post is a file in a git repository. I have the complete history of every change, I can grep through eighteen years of writing, and making a backup is as simple as
git clone. - Portability The web server only needs Apache and a cron job. Moving the blog to another host means: copy one script and one configuration file, point DNS at the new host, done. That matters to me; nobody knows how long my servers will stay where they are.
There are trade-offs of course. A static site needs a “build” step after every change, which takes a few minutes before a new post is visible. And all the dynamic bits (comments, search) need a different solution. That’s exactly what the rest of this article is about. And you can use this knowledge to build your own Hugo-powered blog! I created a git repository hugo-blog-kit to accompany this article and to help you get started.
What happens where?
Before we dive in, here is the big picture. This is what the whole stack looks like, and what happens when you publish a new post:

- You write a post in your browser, in MarkDown language, using the visual editor Sveltia CMS. Sveltia is a single web page which talks to your git repository (I use a Forgejo git server in this article but it can just as well be Codeberg or Github). When you press “Save”, it commits your post (a Markdown text file plus any images) to the git repository. You never touch git yourself, unless you want to.
- Forgejo notices the new commit on the “main” branch and starts a job for Forgejo Actions, its built-in CI/CD system (CI/CD = Continuous Integration/Continuous Delivery, the automated “build, test, deliver” pipeline that software developers use).
- A runner picks up the job. It starts a Docker container from a “builder image” that contains Hugo (turns your Markdown into HTML pages) and Pagefind (creates a search index for the site). The complete website ends up in a single tarball.
- The runner uploads that tarball into Forgejo’s package registry, as a new version of a “generic package”.
- On your web server, a small script sitepull.sh runs from cron every few minutes. It asks the package registry whether there is a newer version of the site tarball, downloads it, verifies its checksum, unpacks it and switches the web site over to it in one atomic step. Right after the switch, it can announce your new posts on Mastodon.
- Apache serves the files to your readers.
- Artalk runs in a Docker container next to Apache and handles the comments. Every new comment goes into a moderation queue, and a small “sidecar” script approves comments from people who have commented before, just like WordPress did.
Note the direction of step 5: the web server pulls the site. Nothing ever pushes to it. That means the build server does not need an SSH key that allows it to write to your web server. If your build server ever gets compromised, your web server is not automatically compromised too. And moving the web server to another host or another provider does not involve any changes on the forge side.
Preamble
This section describes the technical details of our setup, as well as the things which you should have prepared before trying to implement the instructions in this article.
I write this article as someone who is root on all of the servers involved. You don’t have to be: an ordinary account on the forge and a shell account on the web server (member of the docker group) will do, as long as the admins are willing to do a few one-time steps for you. The README of the hugo-blog-kit explains exactly which steps, and how to install everything in your home directory.
Web Hosts
For the sake of this instruction, I will use these hostnames:
- blog.darkstar.lan - the blog itself
- comments.darkstar.lan - the Artalk comment server
- forge.darkstar.lan - your Forgejo server
Setting up your domain (which will hopefully be something else than “darkstar.lan”…) with new hostnames and then setting up web servers for the hostnames in that domain is an exercise left to the reader. Before continuing, please ensure that your equivalents for blog.darkstar.lan and comments.darkstar.lan have a web server running. They don’t have to serve any content yet, but we will add some blocks of configuration to their VirtualHost definitions during the steps outlined in the remainder of this article.
Using a Let’s Encrypt SSL certificate to provide encrypted connections (HTTPS) to your webserver is documented in an earlier blog article.
Note that I am talking about webserver “hosts” but in fact, all of these can be virtual webservers running on the same machine, at the same IP address, served by the same Apache httpd program, but with different DNS entries. There is no need at all for multiple computers when setting up your Slackware Cloud server. In my own setup, the forge and the blog happen to run on different servers, but the instructions work equally well on a single box.
What you should already have
- Docker; see Episode 1.
- A Forgejo server with Actions enabled and at least one runner. Forgejo is a self-hosted git forge, comparable to GitHub or GitLab. Setting up Forgejo deserves an episode of its own (working on it to become Episode 14!). Installing it and registering a runner is well documented in the Forgejo administrator guide. If you already followed Episode 2, you can let your users log in to Forgejo with their Keycloak account. Forgejo version 12 or newer is required for the Sveltia editor; I use Forgejo 15.
- A runner with the label “docker”.
The build job in this article asks for a runner that can start Docker containers. When you register a runner, give it a label like
docker:docker://node:22-bookworm-slim. If the forge is not yours, ask its admin whether such a runner is available; otherwise you can register a runner of your own for your account or repository under Settings > Actions > Runners. - Apache httpd with mod_rewrite, mod_proxy, mod_proxy_http and mod_headers enabled. All of these are part of Slackware’s httpd package.
Port numbers
- The Artalk Docker container listens at the loopback TCP port 23366. That is where the Apache reverse proxy for comments.darkstar.lan directs incoming traffic.
- Nothing else listens on a port: the blog is plain files, and the sitepull script only makes outgoing HTTPS connections.
Secret keys
You will need a few passwords and tokens. Generate random strings with:
$ openssl rand -base64 24
- Artalk admin password (your own login on the comment server). Artalk accepts it as a bcrypt hash, so the password itself never appears in a configuration file:
ARTALK_ADMIN_PASSWORD='(bcrypt)$2y$10$S0me.L0ng.Hash.That.Starts.With.The.Bcrypt.Prefix' - Moderator bot password, for the moderation sidecar. Same procedure.
- A package token for the build job: a Forgejo access token with only the “package: read and write” scope.
- A read token for the web server, only needed if your repository owner is a private organization: a Forgejo access token with only the “package: read” scope.
- A Mastodon token, only if you want your new posts announced on Mastodon: an access token for your Mastodon account with only the “write:statuses” and “profile” scopes.
A bcrypt hash of a password is created with the htpasswd tool which comes with Apache:
$ htpasswd -nbBC 10 '' 'MySecretPassword' | cut -d: -f2
$2y$10$5x0n7Jk1nJ8b0...
File Locations
- The blog’s git repository lives on the forge as darkstar/blog (organization “darkstar”, repository “blog”).
- On the web server, the activated site builds go into: /usr/local/blog/ (the DocumentRoot is the symlink /usr/local/blog/current).
- Images from an old WordPress blog (if you have one) go into: /usr/local/blog-media/
- The sitepull script and its configuration go into: /usr/local/sbin/sitepull.sh and /etc/sitepull/blog.conf
- The Mastodon announcer and its configuration go into: /usr/local/sbin/mastodon-announce.py and /etc/sitepull/mastodon-announce.conf
- The Docker configuration for Artalk goes into: /opt/artalk/
- The Artalk database goes into: /usr/local/artalk/
Server configuration steps
I will break down the story into its main parts:
- Create a Hugo site and put it in a git repository on your forge
- Create a Docker “builder” image containing Hugo and Pagefind
- Prepare the forge: a bot account, a token, and some settings
- Add the build workflow which turns every commit into a site package
- Let the web server pull and activate new packages
- Add comments with Artalk, and a moderation sidecar
- Add the Sveltia CMS editor so you can write posts in your browser
A Hugo site in a git repository
Hugo is a “static site generator”. You give it a directory with content (Markdown files), templates (HTML with placeholders) and a configuration file, and Hugo writes out a complete website: one HTML page per post, archive pages per category and tag, RSS feeds, a sitemap. It is a single program written in Go, and it is ridiculously fast: Alien Pastures, with more than 3,000 pages, is built in well under a minute.
Install Hugo on your desktop
You don’t strictly need Hugo on your own computer, because the runner builds the site. But a local preview while you work on templates is very handy. Download a release from Hugo’s GitHub page.
Note for Slackware 15.0 users: the “extended” Hugo binary is linked against glibc 2.34 or newer, and Slackware 15.0 has glibc 2.33. Use the standard (static) build instead, unless your theme needs the extended features (Sass compilation, mostly). On Slackware -current, both builds work.
$ wget https://github.com/gohugoio/hugo/releases/download/v0.169.0/hugo_0.169.0_linux-amd64.tar.gz
$ tar -xf hugo_0.169.0_linux-amd64.tar.gz hugo
$ mv hugo ~/bin/
$ hugo version
Create the site
$ hugo new project blog --format yaml
$ cd blog
$ git init -b main
That creates the directory structure Hugo expects. The most important parts:
- content/ - your posts and pages, in Markdown
- layouts/ - your own templates, which override the theme’s
- static/ - files that are copied into the website unchanged
- themes/ - the theme(s) you use
- hugo.yaml - the configuration
Pick a theme from the Hugo themes site and add it to the themes/ directory. For Alien Pastures I ported the WordPress theme I had been using for years (Hemingway by Anders Norén) to Hugo, so that the blog looks exactly like it did before. That was a good exercise in learning how Hugo templates work, but a ready-made theme will get you going much faster.
A word of warning: Hugo introduced a new template layout in version 0.146 (2025) and many themes and tutorials out there still use the old one. When you read about templates, make sure the information is recent. The official documentation is always up to date.
Configuration and environments
Instead of a single hugo.yaml, I use a configuration directory with a part for each “environment”. Hugo merges the base configuration with the part for the environment you are building:
config/
_default/hugo.yaml everything that is the same everywhere
production/hugo.yaml https://blog.darkstar.lan/
staging/hugo.yaml a test site, kept out of search engines
This allows the build job to create a test version and the real version of the site from the same commit. I used a staging site at a different hostname for weeks while working on the migration, while the old WordPress blog stayed online.
Here is a shortened config/_default/hugo.yaml to show the important bits:
title: "My Blog"
locale: "en-US"
theme: "mytheme"
# WordPress-style URLs: /my-post/, /tag/slackware/, /category/linux/
taxonomies:
category: categories
tag: tags
permalinks:
page:
posts: "/:slugorcontentbasename/"
term:
tags: "/tag/:slug/"
categories: "/category/:slug/"
pagination:
pagerSize: 5
markup:
goldmark:
renderer:
unsafe: true # allow some raw HTML inside Markdown
params:
artalk:
server: "https://comments.darkstar.lan"
site: "My Blog"
And config/production/hugo.yaml simply contains:
baseURL: "https://blog.darkstar.lan/"
A first post
New posts go into their own directory, together with their images. Hugo calls that a “page bundle”:
content/posts/2026/hello-world/index.md
content/posts/2026/hello-world/screenshot.png
The index.md file starts with “front matter” (the metadata, between the --- lines), followed by the text in Markdown:
---
title: "Hello world"
date: 2026-11-15T12:00:00+01:00
categories: [software]
tags: [slackware]
comments: true
---
My **first** post on my own blogging platform. Here is a picture:

The URL of this post will be https://blog.darkstar.lan/hello-world/ because of the permalinks setting above: the directory name becomes the URL, and it does not change when you edit the title later.
Preview it
$ hugo server --environment staging
Point your browser at http://localhost:1313/ and look at your site. Hugo watches your files and refreshes the page in your browser whenever you save a change.
When you are happy with it, create the repository “blog” in your organization on the forge (I’ll call the organization “darkstar”) and push your site to it. The repository can be private: the forge only hands out the finished website, never the sources.
The builder image
The runner builds the site inside a Docker container. I could install Hugo at the start of every build job, but I prefer a dedicated image with one exact Hugo version inside. A build should never break because “latest” moved to a version that deprecated a template function I use. Upgrading Hugo becomes a conscious decision: build a new image, test it, change one line in the workflow.
Here is the Dockerfile (shortened; the complete one adds OCI labels with version information):
# Hugo builder image for Forgejo Actions.
# The Node base is needed because JavaScript actions such as
# actions/checkout need a node binary inside the job container.
FROM node:22-bookworm-slim
ARG HUGO_VERSION
ARG PAGEFIND_VERSION=1.5.2
RUN apt-get update \
&& apt-get install -y --no-install-recommends ca-certificates curl git jq \
&& rm -rf /var/lib/apt/lists/*
# Fetch the extended Hugo binary and verify it against the upstream
# checksum list before installing it.
RUN set -eu; cd /tmp; \
base="https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}"; \
tgz="hugo_extended_${HUGO_VERSION}_linux-amd64.tar.gz"; \
sums="hugo_${HUGO_VERSION}_checksums.txt"; \
curl -fsSLO "$base/$tgz"; \
curl -fsSLO "$base/$sums"; \
grep " ${tgz}\$" "$sums" | sha256sum -c -; \
tar -xzf "$tgz" -C /usr/local/bin hugo; \
rm -f "$tgz" "$sums"; \
hugo version
# Pagefind builds the static search index after Hugo has run.
RUN npm install -g "pagefind@${PAGEFIND_VERSION}" && pagefind --version
CMD ["/bin/bash"]
Build it and push it into the container registry which is built into Forgejo (here it goes in under user ‘alien’, substitute your own user):
$ docker build --build-arg HUGO_VERSION=0.169.0 \
-t forge.darkstar.lan/alien/hugo-builder:0.169.0 .
$ docker login forge.darkstar.lan
$ docker push forge.darkstar.lan/alien/hugo-builder:0.169.0
Note: Docker stores the login credentials per registry hostname. If your registry is reachable under more than one name, log in with exactly the name you are pushing to. That cost me a “reqPackageAccess” error and some head scratching.
The image contains nothing but public tools, so I made it public. My own version is at forge.slackware.nl/alienbob/hugo-builder and you are welcome to use it as-is or copy the Dockerfile.
Prepare the forge
The build job needs to upload the finished site into the package registry, and for that it needs an access token. That token should be able to do nothing else.
You don’t need to be the admin of the forge for this. Most people who use somebody else’s Forgejo server won’t be, and that’s fine: create the token in your own account. Go to Settings > Applications, generate a new token, and select only the scope package: Read and Write. A token with only that scope cannot read or change any of your repositories, issues or settings, even though it belongs to your account. If the blog repository belongs to an organization (I use “darkstar” in this article), make sure you are a member of a team in that organization with write access to packages.
In the repository, go to Settings > Actions and add:
- Variables
SITE_ENVS=production(orstaging productionif you also want a test site)PKG_OWNER=darkstar(the organization, or your user name if the repository is yours)PKG_USER= your user name
- Secrets
PKG_TOKEN= the token you just created
If you are the admin of your forge
Then I recommend a separate bot account, so that the token is not tied to your personal account at all. That is how I did it. Create the account from the command line on your Forgejo server:
# forgejo admin user create --username blogbot \
--email blogbot@darkstar.lan --random-password \
--must-change-password=false
Do not forget that last parameter. Without it, the account is created with a “must change password” flag, and every API call with its tokens is refused until someone logs in once and changes the password. Ask me how I know…
Make the bot a member of a team in the “darkstar” organization that has write access to packages. Then log in as the bot (or use the admin’s “sudo” feature), create the token with only the scope package: Read and Write, and use blogbot as the PKG_USER variable.
The build workflow
Forgejo Actions reads its workflows from the .forgejo/workflows/ directory in your repository. The syntax is the same as GitHub Actions. Create .forgejo/workflows/build.yaml:
name: build-and-publish
on:
push:
branches: [main]
# Nightly rebuild, so posts with a future date appear on time.
schedule:
- cron: '23 4 * * *'
workflow_dispatch:
jobs:
build:
# Must match a label of your runner.
runs-on: docker
container:
image: forge.darkstar.lan/alien/hugo-builder:0.169.0
env:
FORGE_URL: ${{ github.server_url }}
SITE_ENVS: ${{ vars.SITE_ENVS }}
PKG_OWNER: ${{ vars.PKG_OWNER }}
PKG_USER: ${{ vars.PKG_USER }}
PKG_TOKEN: ${{ secrets.PKG_TOKEN }}
KEEP_VERSIONS: '3'
steps:
- uses: actions/checkout@v4
- name: Build and publish site packages
run: bash .forgejo/scripts/build-publish.sh
The schedule deserves a word. Hugo leaves out posts with a date in the future. If you write a post today and give it next Monday’s date, it appears with the first nightly build after that date. A simple way to schedule posts, without any “scheduler” running anywhere.
The real work happens in .forgejo/scripts/build-publish.sh. It builds the site once per environment, adds the search index, and uploads the result as a new version of a generic package:
#!/bin/bash
# build-publish.sh - build the Hugo site once per environment and upload
# each build as a version of a Forgejo generic package.
#
# Package name : blog-<environment>
# Version : <UTC timestamp>-<12 char commit sha>
# The timestamp prefix makes versions sort correctly as
# plain strings, which is how the web host picks "newest".
# Files : site.tar.gz and site.tar.gz.sha256
set -euo pipefail
: "${FORGE_URL:?FORGE_URL not set}"
: "${PKG_OWNER:?PKG_OWNER not set}"
: "${PKG_USER:?PKG_USER not set}"
: "${PKG_TOKEN:?PKG_TOKEN not set}"
SITE_ENVS=${SITE_ENVS:-staging}
KEEP_VERSIONS=${KEEP_VERSIONS:-10}
SHA=${GITHUB_SHA:-$(git rev-parse HEAD)}
VERSION="$(date -u +%Y%m%dT%H%M%SZ)-${SHA:0:12}"
PKG_API="$FORGE_URL/api/packages/$PKG_OWNER/generic"
AUTH=(--user "$PKG_USER:$PKG_TOKEN")
for env in $SITE_ENVS; do
pkg="blog-$env"
out="$PWD/_out/$env"
rm -rf "$out"
mkdir -p "$out"
echo ">>> Building environment '$env' as $pkg $VERSION"
# Drafts are never built: packages may be publicly downloadable.
hugo --environment "$env" --minify \
--destination "$out/public" --cleanDestinationDir
# Static full-text search index (served from /pagefind/).
pagefind --site "$out/public" --silent
tar -C "$out/public" -czf "$out/site.tar.gz" .
(cd "$out" && sha256sum site.tar.gz > site.tar.gz.sha256)
# Upload the tarball first and the checksum last. The web host treats
# a version without a checksum as "not ready yet" and retries later.
for f in site.tar.gz site.tar.gz.sha256; do
curl -fsS "${AUTH[@]}" --upload-file "$out/$f" \
"$PKG_API/$pkg/$VERSION/$f"
done
echo ">>> Uploaded $pkg $VERSION"
# Keep only the newest KEEP_VERSIONS versions in the registry. The
# ones that remain are the rollback window for the web host.
curl -fsS "${AUTH[@]}" \
"$FORGE_URL/api/v1/packages/$PKG_OWNER?type=generic&q=$pkg&limit=50" \
| jq -r --arg n "$pkg" \
'[.[] | select(.name == $n) | .version] | sort | reverse | .[]' \
| tail -n +"$((KEEP_VERSIONS + 1))" \
| while read -r old; do
echo ">>> Pruning $pkg $old"
curl -fsS "${AUTH[@]}" -X DELETE "$PKG_API/$pkg/$old"
done
done
Commit both files and push. In the “Actions” tab of your repository you can watch the job run. When it shows a green checkmark, look at the “Packages” tab of the “darkstar” organization: there should be a package “blog-production” with one version.
If your job stays in the “Waiting” state forever, then no runner has the label “docker”. That happened to me: my existing runner only had labels for running Slackware build jobs. Adding a docker label to the runner’s configuration file and restarting the runner fixed it.
Search with Pagefind
You may have noticed the pagefind command in the build script. Search is one of those things that you think needs a server, but Pagefind proves otherwise. After Hugo has written the site, Pagefind reads all the HTML files and creates a compact search index, split into small chunks. A bit of JavaScript on your search page downloads only the chunks it needs for the words someone types, so even a large blog gets a fast search without any search server.
The search page in your theme needs only this:
<link href="/pagefind/pagefind-ui.css" rel="stylesheet">
<div id="search"></div>
<script src="/pagefind/pagefind-ui.js"></script>
<script>
window.addEventListener('DOMContentLoaded', function () {
new PagefindUI({ element: '#search', showImages: false });
});
</script>
Add a data-pagefind-body attribute to the HTML element that holds the text of your posts, so that Pagefind indexes your articles and not the sidebar that is repeated on every page.
The web server pulls the site
Why pull instead of push?
The common way to deploy a website from a CI job is to let the job copy the files to the web server with rsync over SSH. That means storing an SSH private key with write access to your web server in the CI system. I don’t want write-capable SSH keys lying around on Internet-connected machines. And when I move my web server to another provider, I don’t want to touch my build setup.
So the web server fetches the site itself. All it needs is outgoing HTTPS to the forge, and (if your organization is private) a token that can only read packages.
The sitepull script
Save this as /usr/local/sbin/sitepull.sh and make it executable:
#!/bin/bash
# sitepull.sh - pull the newest static site build from a Forgejo generic
# package registry and activate it with an atomic symlink switch.
#
# Usage: sitepull.sh /path/to/site.conf
#
# Layout under SITE_ROOT:
# current -> releases/<version> (Apache DocumentRoot)
# releases/ one directory per activated build
# incoming/ temporary download area
# PIN optional; contains a version string to stay on
#
# Rollback: echo <version> > $SITE_ROOT/PIN (next run switches to it)
# Resume : rm $SITE_ROOT/PIN (follow newest again)
#
# Hook: POST_ACTIVATE in the configuration names a command that runs right
# after each switch, when the new build is live (for instance
# mastodon-announce.py to toot new posts). It gets SITE_ROOT, SITE_VERSION
# and SITE_PREVIOUS in its environment. If it fails, sitepull runs it again
# on every following round until it succeeds; a failing hook never stops
# or undoes the switch itself.
set -euo pipefail
umask 022
CONF=${1:?Usage: $0 /path/to/site.conf}
# shellcheck source=/dev/null
. "$CONF"
: "${FORGE_URL:?FORGE_URL not set in $CONF}"
: "${PKG_OWNER:?PKG_OWNER not set in $CONF}"
: "${PKG_NAME:?PKG_NAME not set in $CONF}"
: "${SITE_ROOT:?SITE_ROOT not set in $CONF}"
KEEP_RELEASES=${KEEP_RELEASES:-5}
MIN_FILES=${MIN_FILES:-50}
POST_ACTIVATE=${POST_ACTIVATE:-}
HOOK_TIMEOUT=${HOOK_TIMEOUT:-300}
TAG="sitepull[$PKG_NAME]"
log() { logger -t "$TAG" -- "$*"; }
die() { log "ERROR: $*"; echo "$TAG ERROR: $*" >&2; exit 1; }
CURL=(curl -fsS --retry 2 --connect-timeout 20 --max-time 900)
if [ -n "${READ_TOKEN:-}" ]; then
CURL+=(-H "Authorization: token $READ_TOKEN")
fi
mkdir -p "$SITE_ROOT/releases" "$SITE_ROOT/incoming"
# One run per site at a time; a slow download must not overlap the next
# cron tick.
exec 9>"$SITE_ROOT/.lock"
flock -n 9 || exit 0
# Run the POST_ACTIVATE hook; remember a failure so the next round retries.
run_hook() {
[ -n "$POST_ACTIVATE" ] || return 0
# Word splitting on purpose: POST_ACTIVATE is "command [arguments]".
# shellcheck disable=SC2086
if SITE_ROOT="$SITE_ROOT" SITE_VERSION="$1" SITE_PREVIOUS="${2:-}" \
timeout "$HOOK_TIMEOUT" $POST_ACTIVATE </dev/null; then
rm -f "$SITE_ROOT/.hook-retry"
else
echo "$1" > "$SITE_ROOT/.hook-retry"
log "post-activate hook failed for $1, will retry next round"
fi
}
# Decide which version we want: the pinned one, or the newest published.
if [ -s "$SITE_ROOT/PIN" ]; then
WANT=$(tr -d '[:space:]' < "$SITE_ROOT/PIN")
else
LIST=$("${CURL[@]}" \
"$FORGE_URL/api/v1/packages/$PKG_OWNER?type=generic&q=$PKG_NAME&limit=50") \
|| die "cannot query the package list at $FORGE_URL"
WANT=$(printf '%s' "$LIST" | jq -r --arg n "$PKG_NAME" \
'[.[] | select(.name == $n) | .version] | sort | last // empty')
fi
if [ -z "$WANT" ]; then
log "no published version yet"
exit 0
fi
case "$WANT" in
*[!A-Za-z0-9._-]*) die "refusing odd version string '$WANT'" ;;
esac
CUR=""
if [ -L "$SITE_ROOT/current" ]; then
CUR=$(basename "$(readlink "$SITE_ROOT/current")")
fi
if [ "$WANT" = "$CUR" ]; then
[ -e "$SITE_ROOT/.hook-retry" ] && run_hook "$CUR"
exit 0
fi
REL="$SITE_ROOT/releases/$WANT"
if [ ! -d "$REL" ]; then
TMP=$(mktemp -d "$SITE_ROOT/incoming/$WANT.XXXXXX")
trap 'rm -rf "$TMP"' EXIT
BASE="$FORGE_URL/api/packages/$PKG_OWNER/generic/$PKG_NAME/$WANT"
# The CI job uploads the checksum last, so a missing checksum means the
# upload is still in progress. Fetch it first and retry later if absent.
if ! "${CURL[@]}" -o "$TMP/site.tar.gz.sha256" "$BASE/site.tar.gz.sha256" 2>/dev/null; then
log "version $WANT not complete yet, will retry"
exit 0
fi
"${CURL[@]}" -o "$TMP/site.tar.gz" "$BASE/site.tar.gz" \
|| die "download of $WANT failed"
(cd "$TMP" && sha256sum -c --quiet site.tar.gz.sha256) \
|| die "checksum mismatch for $WANT"
# Refuse archives with absolute paths, parent directory components,
# symlinks or hard links. A Hugo build contains none of these.
if tar -tzf "$TMP/site.tar.gz" | grep -qE '^/|(^|/)\.\.(/|$)'; then
die "unsafe path names in $WANT"
fi
if tar -tvzf "$TMP/site.tar.gz" | grep -q '^[lh]'; then
die "links found in $WANT"
fi
mkdir "$TMP/tree"
tar -xzf "$TMP/site.tar.gz" -C "$TMP/tree" \
--no-same-owner --no-same-permissions
chmod -R u=rwX,go=rX "$TMP/tree"
# Sanity checks against an empty or truncated build.
[ -f "$TMP/tree/index.html" ] || die "$WANT has no index.html"
N=$(find "$TMP/tree" -type f | wc -l)
[ "$N" -ge "$MIN_FILES" ] || die "$WANT has only $N files (minimum $MIN_FILES)"
mv "$TMP/tree" "$REL"
fi
# Atomic switch: create the new symlink beside the old one, then rename
# it over the old one. Apache never sees a missing DocumentRoot.
ln -sfn "releases/$WANT" "$SITE_ROOT/current.new"
mv -Tf "$SITE_ROOT/current.new" "$SITE_ROOT/current"
log "activated $WANT (previous: ${CUR:-none})"
run_hook "$WANT" "$CUR"
# Remove old releases, never the active one.
find "$SITE_ROOT/releases" -mindepth 1 -maxdepth 1 -type d -printf '%f\n' \
| sort | head -n -"$KEEP_RELEASES" \
| while read -r old; do
[ "$old" = "$WANT" ] || rm -rf -- "${SITE_ROOT:?}/releases/$old"
done
A few things in there are worth pointing out, because they make the difference between “works on a sunny day” and “never breaks the site”:
- The build job uploads the checksum file last. The script fetches the checksum first. If it is not there yet, the upload is still in progress, and the script simply tries again at the next cron run. You’ll never activate a half-uploaded site.
- The new site is unpacked next to the old one, and then a symlink is switched over with an atomic
mv. Apache never sees a missing or half-filled DocumentRoot. - Old builds are kept on disk. If a new build turns out to be broken, you go back with one command:
echo <version> > /usr/local/blog/PIN. Remove the PIN file when the problem is fixed. - After the switch, the script can run a command of your choice: the
POST_ACTIVATEhook. At that moment the new build is live, which makes it the perfect place to tell the world about a new post. More about that in “Announcing new posts on Mastodon” below. Without aPOST_ACTIVATEline in the configuration, nothing happens.
The configuration file /etc/sitepull/blog.conf:
FORGE_URL=https://forge.darkstar.lan
PKG_OWNER=darkstar
PKG_NAME=blog-production
SITE_ROOT=/usr/local/blog
# Only needed when the package owner is not publicly visible.
# Use a token with the package READ scope only.
READ_TOKEN=
KEEP_RELEASES=5
MIN_FILES=50
Make that file readable only for the account that runs the script if it contains a token. Then add a cron job, for instance in the crontab of a dedicated unprivileged user that owns /usr/local/blog:
*/5 * * * * /usr/local/sbin/sitepull.sh /etc/sitepull/blog.conf
Run the script once by hand and check your /var/log/messages for the “activated” message.
The Apache virtual host
The VirtualHost for blog.darkstar.lan gets this configuration block:
# The symlink is switched atomically by sitepull.sh.
DocumentRoot "/usr/local/blog/current"
<Directory "/usr/local/blog">
Options FollowSymLinks
AllowOverride None
Require all granted
</Directory>
# Hugo's own "page not found" page, in the blog's layout.
ErrorDocument 404 /404.html
Check your Apache configuration for global Alias directives before you start. My server had an old Alias /css in a global configuration file which silently hijacked the stylesheet of the new blog. I moved all the theme’s files under a /_ap/ prefix (“Alien Pastures”) to stay clear of such collisions.
Comments with Artalk
Artalk is a self-hosted comment system: a small server written in Go, plus a JavaScript widget that you put on your pages. Readers enter a name and an email address (no account, no third-party login), and the comment is stored in a SQLite database on your own server. It supports threaded replies, email notifications, a moderation queue, Akismet spam checking, and it can import comments from other systems.
I looked at several alternatives. Artalk was the winner for me. It does not require any credentials like OpenID Connect or social login for commenters. People should be able to comment with just a name and an email address, as they could on WordPress. It also offers a moderation queue for comments from new people, and a good import tool.
Docker Compose
Create /opt/artalk/docker-compose.yml. All of Artalk’s settings can be given as environment variables, so you never have to edit its own configuration file:
services:
artalk:
image: artalk/artalk-go:2.10.1
container_name: artalk
restart: unless-stopped
# Only Apache on this host talks to Artalk; it terminates TLS.
ports:
- "127.0.0.1:23366:23366"
volumes:
- /usr/local/artalk:/data
environment:
TZ: "Europe/Amsterdam"
ATK_TIMEZONE: "Europe/Amsterdam" # the default is Asia/Shanghai
ATK_LOCALE: "en"
ATK_SITE_DEFAULT: "My Blog"
ATK_SITE_URL: "https://blog.darkstar.lan"
ATK_TRUSTED_DOMAINS: "https://blog.darkstar.lan"
# Behind Apache: take the reader's address from X-Forwarded-For,
# otherwise rate limits and Akismet only see the proxy.
ATK_HTTP_PROXY_HEADER: "X-Forwarded-For"
# Your admin account, created or updated at every start.
ATK_ADMIN_USERS_0_NAME: "alien"
ATK_ADMIN_USERS_0_EMAIL: "alien@darkstar.lan"
ATK_ADMIN_USERS_0_PASSWORD: "${ARTALK_ADMIN_PASSWORD}"
ATK_ADMIN_USERS_0_BADGE_NAME: "Post author"
ATK_ADMIN_USERS_0_BADGE_COLOR: "#1abc9c"
# A second admin, used only by the moderation sidecar.
ATK_ADMIN_USERS_1_NAME: "moderator-bot"
ATK_ADMIN_USERS_1_EMAIL: "moderator-bot@darkstar.lan"
ATK_ADMIN_USERS_1_PASSWORD: "${ARTALK_BOT_PASSWORD}"
ATK_ADMIN_USERS_1_RECEIVE_EMAIL: "false"
# Moderation and anti-spam.
ATK_MODERATOR_PENDING_DEFAULT: "true" # every new comment waits
ATK_MODERATOR_AKISMET_KEY: "${ARTALK_AKISMET_KEY}"
ATK_CAPTCHA_ALWAYS: "false"
ATK_CAPTCHA_ACTION_LIMIT: "3"
ATK_CAPTCHA_ACTION_RESET: "60"
# Mail: notify me about new comments.
ATK_EMAIL_ENABLED: "true"
ATK_EMAIL_SEND_TYPE: "smtp"
ATK_EMAIL_SMTP_HOST: "${ARTALK_SMTP_HOST}"
ATK_EMAIL_SMTP_PORT: "${ARTALK_SMTP_PORT}"
ATK_EMAIL_SMTP_USERNAME: "${ARTALK_SMTP_USERNAME}"
ATK_EMAIL_SMTP_PASSWORD: "${ARTALK_SMTP_PASSWORD}"
ATK_EMAIL_SEND_ADDR: "${ARTALK_SMTP_FROM}"
ATK_EMAIL_SEND_NAME: "My Blog"
ATK_ADMIN_NOTIFY_EMAIL_ENABLED: "true"
ATK_ADMIN_NOTIFY_NOTIFY_PENDING: "true"
# Look and feel: pixel-art avatars for people without a Gravatar,
# no emoticon list from a CDN, no voting.
ATK_FRONTEND_GRAVATAR_PARAMS: "sha256=1&d=retro&s=240"
ATK_FRONTEND_EMOTICONS: "false"
ATK_FRONTEND_VOTE: "false"
The secrets go into /opt/artalk/.env, which Docker Compose reads automatically. Make it readable only by root (chmod 600 /opt/artalk/.env):
ARTALK_ADMIN_PASSWORD='(bcrypt)$2y$10$REPLACE_WITH_YOUR_HASH'
ARTALK_BOT_PASSWORD='(bcrypt)$2y$10$REPLACE_WITH_THE_BOT_HASH'
ARTALK_AKISMET_KEY='REPLACE'
ARTALK_SMTP_HOST='smtp.darkstar.lan'
ARTALK_SMTP_PORT='587'
ARTALK_SMTP_USERNAME='REPLACE'
ARTALK_SMTP_PASSWORD='REPLACE'
ARTALK_SMTP_FROM='comments@darkstar.lan'
Note the single quotes around the bcrypt hashes. A bcrypt hash contains $ characters, and without single quotes Docker Compose tries to expand $2y and $10 as variables, silently mangling your password hash. And yes, it really is ATK_ADMIN_NOTIFY_NOTIFY_PENDING with the double “NOTIFY”: the setting notify_pending lives inside the admin_notify section of Artalk’s configuration.
Start it:
# mkdir -p /usr/local/artalk
# cd /opt/artalk
# docker compose up -d
# docker compose logs -f
Apache reverse proxy for comments.darkstar.lan
These are the bits that you need to copy into the Apache VirtualHost block of the comments server.
ProxyRequests Off
ProxyPreserveHost On
ProxyPass "/" "http://127.0.0.1:23366/"
ProxyPassReverse "/" "http://127.0.0.1:23366/"
RequestHeader set X-Forwarded-Proto "https"
One thing to watch out for: when you are logged in as admin, Artalk’s comment box shows a “Dashboard” link that opens the admin panel in a frame on your blog page. If your Apache configuration sends an X-Frame-Options header (many hardening guides recommend that), the browser refuses to show any content from comments.darkstar.lan inside your blog, with an unhelpful “refused to connect”. The fix is a Content Security Policy that explicitly allows your blog to frame the comment server. Modern browsers ignore X-Frame-Options when frame-ancestors is present:
Header always set Content-Security-Policy "frame-ancestors https://blog.darkstar.lan"
Show the comments on your pages
In your theme, add a partial template (for instance layouts/_partials/comments.html) and include it at the bottom of your post template:
{{- with site.Params.artalk }}
<div id="comments"></div>
<link href="{{ .server }}/dist/Artalk.css" rel="stylesheet">
<script src="{{ .server }}/dist/Artalk.js"></script>
<script>
Artalk.init({
el: '#comments',
server: '{{ .server }}',
site: '{{ .site }}',
pageKey: '{{ $.RelPermalink }}',
pageTitle: '{{ $.Title }}',
// Oldest comments first, like WordPress.
listFetchParamsModifier: function (params) { params.sort_by = 'date_asc'; }
});
</script>
{{- end }}
The pageKey is how Artalk knows which comments belong to which page. Use the page’s path, so that comments survive a change of domain name.
To reply to a comment as the blog’s author: just type your admin name and email address into the comment box. Artalk recognizes them and asks for your password before it accepts the comment. Nobody can post as you without that password. Once you are logged in, your replies are published immediately and carry your “Post author” badge.
Moderation, the WordPress way
With ATK_MODERATOR_PENDING_DEFAULT set to “true”, every new comment waits in the moderation queue until you approve it. That is safe, but it gets tedious. WordPress had a nice rule for this: “comment author must have a previously approved comment”. Your regular readers get through immediately, but the unknown visitors have to wait for you to process the moderation queue.
Artalk does not have that rule, so I wrote a small Python script that adds it. It runs from cron every minute, looks at the comments that arrived since its previous run, and decides:
| Comment | Result |
|---|---|
| Same name and email address already has an approved comment | approved, unless Akismet calls it spam or it contains more than 2 links |
| Uses the name or the email address of an admin | stays pending, and gets a warning label in front of the text |
| Anybody else | stays pending, for you to review |
That second rule is there because Artalk only asks for a password when both your name and your email address are entered. Someone who uses your name with a different email address would end up in the queue anyway, but now you can’t approve it by accident.
The script logs in as the “moderator-bot” admin account that we defined in the Docker Compose file, so your own password is never stored in a plain text file. It only uses the Python standard library, so there is nothing to install. You can download it, with its configuration example and a logrotate file, from the artalk directory of the hugo-blog-kit.
# install -m 755 artalk-moderator.py /opt/artalk/
# install -m 600 moderator.conf.example /opt/artalk/moderator.conf
# vi /opt/artalk/moderator.conf # bot password, Akismet key
# python3 /opt/artalk/artalk-moderator.py --check
The --check verifies the database, the bot’s login and your Akismet key. Then add it to root’s crontab:
* * * * * /usr/bin/python3 /opt/artalk/artalk-moderator.py >> /var/log/artalk-moderator.log 2>&1
Every decision ends up as one line in the log, so you can always see why a comment was or wasn’t approved:
id=20702 user='erics' page=/my-post/ -> approved: known commenter (1 approved), Akismet ham
id=20700 user='alien' page=/my-post/ -> flagged, stays pending: impersonation: uses the name of admin "alien"
Writing posts in your browser with Sveltia CMS
Sveltia CMS is a “Git-based headless CMS”. Behind that mouthful hides something quite elegant. It is a single web page, which you put on your blog at https://blog.darkstar.lan/admin/. When you open it, you log in at your Forgejo server, and from then on Sveltia reads and writes the files in your blog’s git repository through Forgejo’s API. There is no server-side component, no database, no login system of its own. The web server only serves two static files.
Sveltia is a modern rewrite of Netlify CMS (later Decap CMS) and it supports Forgejo directly. It needs Forgejo 12 or newer.
Register an OAuth2 application
In Forgejo, go to Settings > Applications (for your own account, or the organization’s) and create a new OAuth2 application:
- Application name: My Blog CMS
- Redirect URI: https://blog.darkstar.lan/admin/ (with the trailing slash)
- Confidential client: unticked
Forgejo shows you a Client ID and a Client Secret. You only need the Client ID. Sveltia runs in the browser, so it cannot keep a secret anyway; it uses PKCE instead, a method where the browser proves for every single login that it is the same browser that started that login.
Allow your blog to talk to the forge (CORS)
The Sveltia page on blog.darkstar.lan sends API requests to forge.darkstar.lan. Browsers block such “cross-origin” requests unless the server explicitly allows them. Add this to Forgejo’s app.ini and restart Forgejo. This is the one step in this article that needs the forge’s admin: if that is not you, ask them to add your blog’s address.
[cors]
ENABLED = true
ALLOW_DOMAIN = https://blog.darkstar.lan
METHODS = GET,HEAD,POST,PUT,PATCH,DELETE,OPTIONS
HEADERS = Content-Type,User-Agent,Authorization
ALLOW_CREDENTIALS = false
Pay attention to the HEADERS line. Forgejo’s default list does not contain Authorization, and without it you can log in perfectly fine, after which every API call fails.
If you protect your forge with Anubis against AI scrapers (as I do, see my article about the Slackware forge being abused), make sure that /api/ and the token endpoint /login/oauth/access_token bypass Anubis. Sveltia’s API calls come from another website and carry no Anubis cookie, so a challenge page would break them. The login page itself can stay behind Anubis.
So what happens if you are not the admin of your forge, and the admin does not want to touch the CORS settings? There is a way around it that only involves your own web server. Let Apache pass the editor’s API calls on to the forge, under the blog’s own address. Add the following to the VirtualHost block of your blog’s webserver:
SSLProxyEngine on
ProxyPass "/_forge/api/" "https://forge.darkstar.lan/api/"
ProxyPassReverse "/_forge/api/" "https://forge.darkstar.lan/api/"
Then we make two changes to the Sveltia configuration (see further down for the details of static/admin/config.yml).
Point Sveltia’s api_root at https://blog.darkstar.lan/_forge/api/v1 instead of https://forge.darkstar.lan/api/v1 and add auth_methods: [token]. The browser now only ever talks to your blog, so no CORS is involved.
There’s a price to pay of course. Instead of the comfortable “Sign in with Forgejo”, you sign in once with a personal access token (scopes: user read, repository and issue read/write), which you create in your forge account. I tested this on my own staging site with the forge’s CORS setting switched off, and the whole cycle of draft, review and publish worked. The hugo-blog-kit README describes both variants.
The admin page
Create two files in your site’s static/ directory. The first one is static/admin/index.html:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="robots" content="noindex, nofollow">
<title>My Blog - write</title>
<script src="https://unpkg.com/@sveltia/cms@0.245.1/dist/sveltia-cms.js"
integrity="sha384-WtLM0kE6Istn0n75BQVe+QHHleDS926pjdktjJ16OITlVqpJFAiD69ErfPcwrBvB"
crossorigin="anonymous"></script>
</head>
<body></body>
</html>
The code is always downloaded from unpkg.com. I pin an exact version of Sveltia, and the integrity attribute makes the browser refuse the script if the file on the CDN does not match. Sveltia releases a new version almost every day and I’d rather upgrade deliberately than break my editor unwittingly.
The second file, static/admin/config.yml, tells Sveltia where your repository is and what a post looks like:
backend:
name: gitea # also the right name for Forgejo
repo: darkstar/blog
branch: main
base_url: https://forge.darkstar.lan
api_root: https://forge.darkstar.lan/api/v1
app_id: 12345678-abcd-ef01-2345-6789abcdef01 # your Client ID
# Drafts live on their own branch with a pull request, so they never
# reach "main" and never trigger a build. "Publish" merges them.
publish_mode:
type: editorial_workflow
direct_publish: true
media_folder: static/images
public_folder: /images
collections:
- name: posts
label: Posts
label_singular: Post
folder: content/posts
# content/posts/2026/<name>/index.md, images in the same folder.
path: "{{year}}/{{slug}}/index"
extension: md
format: yaml-frontmatter
create: true
media_folder: ""
public_folder: ""
fields:
- { label: Title, name: title, widget: string }
- label: Body
name: body
widget: markdown
editor_components: [image, code-block, table, hr]
- label: Publication date
name: date
widget: datetime
default: "{{now}}"
format: "YYYY-MM-DDTHH:mm:ssZ"
- label: Categories
name: categories
widget: select
multiple: true
options:
- { label: Linux, value: linux }
- { label: Software, value: software }
- { label: Tags, name: tags, widget: list, required: false }
- { label: Allow comments, name: comments, widget: boolean, default: true }
Commit, push, wait for the build, and open https://blog.darkstar.lan/admin/. Click “Sign in with Forgejo”, approve the “Authorize My Blog CMS?” question on your forge, and you’re in.
Drafts, review, publish
I use Sveltia’s “editorial workflow”. When you save a new post, Sveltia creates a branch cms/posts/<name> and a pull request on the forge. Your post can be a Draft, In Review, or Ready, and none of that triggers a build, because the build workflow only reacts to the “main” branch. When you click “Publish”, Sveltia merges the pull request into main. That push starts the build, and a few minutes later your post is on your blog.
One thing to get used to: your blog’s repository now has two writers. Every “Publish” in Sveltia is a commit on the forge. If you also work on your theme in a local clone, always start with a git pull (and I recommend git config pull.rebase true in that clone), or git will refuse your next push.
Making the editor feel like WordPress
Out of the box, Sveltia’s editor gives you bold, italic, strikethrough, links, headings, lists, quotes, code blocks and images. That’s a good start, but I am used to the WordPress classic editor. I needed to add the missing functionality that allows me to keep on writing articles in my own recognizable style.
Sveltia can be extended with your own “editor components” through a small JavaScript API. I wrote a few, in one file that is loaded right after Sveltia:
- Image with size and alignment: Choose icon (64 px), small, medium, full width, original or a custom width; left, right, centred or none; a caption; and a link to the full-size image or to a web address. It is stored as a Hugo “shortcode” in the Markdown text, and a template in my theme creates real resized copies of the image (plus a double-size version for sharp display on high-resolution screens), just like WordPress made its thumbnails.
- Coloured text: I added the colours I used to use.
- Underlined text, a YouTube video (click-to-load, nothing is loaded from Google until the reader clicks “Play”), and the "Continue reading" cut.
- A preview pane that uses the blog’s own stylesheet, so the preview looks like the published post.
To show you how little code such a component needs, here is the coloured text button:
CMS.registerEditorComponent({
id: 'colored-text',
label: 'Coloured text',
icon: 'format_color_text',
trigger: 'button',
mode: 'dialog',
summary: '{{text}}',
fields: [
{ name: 'text', label: 'Text', widget: 'string' },
{ name: 'color', label: 'Colour', widget: 'select', default: '#008000',
options: [ { label: 'Green', value: '#008000' },
{ label: 'Orange', value: '#ff6600' },
{ label: 'Red', value: '#ff0000' } ] }
],
// How to recognize it in the Markdown text...
pattern: /<span style="color: (#[0-9a-fA-F]{6});">([^<]*)<\/span>/,
fromBlock: function (m) { return { color: m[1], text: m[2] }; },
// ...and how to write it.
toBlock: function (v) {
return '<span style="color: ' + v.color + ';">' + v.text + '</span>';
},
toPreview: function (v) {
return '<span style="color: ' + v.color + ';">' + v.text + '</span>';
}
});
Add colored-text to the editor_components list of the Body field in config.yml, and the button appears in the toolbar. A complete extension file with all of these components is in the hugo-blog-kit, for you to borrow: editor-extensions.js, and the theme’s image shortcode that goes with it.
A small Hugo template change rounds it off: in WordPress, I opened practically every external link in a new browser tab. Markdown has no syntax for that, but Hugo lets you override how links are rendered. A “render hook” in my theme (layouts/_markup/render-link.html) adds target="_blank" to every link that points to another website. I never have to think about it again :-)
Announcing new posts on Mastodon
On WordPress, the Jetpack plugin posted a link to every new article on my Mastodon account. Jetpack did that from inside WordPress, at the moment I pressed “Publish”. A static site has no such moment. Pressing “Publish” in Sveltia only starts a build, and the post appears on the blog some minutes later, when sitepull has fetched the new site.
So that sitepull step is where the announcement happens. The sitepull script has a hook which runs right after it switches to a new build, and a small Python script mastodon-announce.py (standard library only, like the moderation sidecar) hangs from that hook. This has some nice properties:
- The toot goes out when the post is really live. A toot from the CI job would link to a page that does not exist yet.
- A post with a date in the future is announced when the nightly build after that date publishes it.
- The Mastodon token lives on the web server and nowhere else; the forge and the runner never see it.
How does the script know which posts are new?
The theme writes a small file /_theme/toots.json with every build, listing the 50 newest posts: their title, URL, date, tags and a fixed id (the post’s folder in the repository). The script remembers the ids of the posts it has seen, and toots every post it has not seen before. Editing a published post, giving it a new title, or rolling back to an older build and forward again, toots nothing. On its first run, the script marks all listed posts as seen without tooting anything, so you don’t flood your followers with your entire archive.
There are a few safety nets, because a misbehaving bot is the last thing you want on your Mastodon account:
- Posts that are dated more than 30 days ago are never tooted automatically.
- If more than three new posts show up in a single build, that’s a mass change (for instance a re-import), not new writing. Nothing is tooted and you get an email from cron. You then pick the ones you do want announced.
- If your Mastodon server is unreachable, sitepull retries on every round until it works. Every toot carries an
Idempotency-Keyheader, so a toot whose answer got lost on the way is not posted twice.
A toot looks like this; the text is the post’s title, the hashtags come from its tags:
Slackware Cloud Server Series, Episode 13: Blogging Platform
https://blog.darkstar.lan/slackware-cloud-server-series-episode-13-blogging-platform/
#Slackware #SlackwareCloudServer #Hugo #Forgejo #Artalk
Mastodon fetches the page to build a preview card below the toot. For a good-looking card, the theme adds a description and an image (the first picture of the post) to every page as og:description and og:image meta tags.
In Sveltia, two new fields under the post body give you control: Toot text, if you want to write the announcement yourself instead of using the title, and Announce on Mastodon, a checkbox to keep a post off Mastodon.
The setup takes five minutes. If you followed Episode 7, your account lives at https://mastodon.darkstar.lan/, but any Mastodon server will do.
First, create the token. In Mastodon, go to Preferences > Development > New application, give it a name (the name of your blog is fine), and in the list of scopes, untick “read”, “write” and “follow” and tick only write:statuses and profile. The script can then post toots, and nothing else: it can’t read your timeline or your direct messages, or follow anyone. Save the application, open it again, and copy “Your access token”.
Install the script and its configuration (both are in the hugo-blog-kit repository), and make the configuration readable only by the account that runs sitepull, because it contains the token:
# install -m 755 mastodon-announce.py /usr/local/sbin/
# install -o someuser -m 600 mastodon-announce.conf.example /etc/sitepull/mastodon-announce.conf
The important lines in /etc/sitepull/mastodon-announce.conf are:
MASTODON_URL=https://mastodon.darkstar.lan
MASTODON_TOKEN=<your access token>
SITE_DIR=/usr/local/blog/current
STATE=/usr/local/blog/mastodon-state.json
LOG_FILE=/usr/local/blog/mastodon-announce.log
EXTRA_HASHTAGS=#Slackware
As the account that runs sitepull, check the configuration, and then let the script record the posts that are already on your blog:
$ python3 /usr/local/sbin/mastodon-announce.py /etc/sitepull/mastodon-announce.conf --check
$ python3 /usr/local/sbin/mastodon-announce.py /etc/sitepull/mastodon-announce.conf --seed
Running the above two commands is mandatory before you put this into production!
Finally, switch on the hook by adding this line to /etc/sitepull/blog.conf:
POST_ACTIVATE="/usr/bin/python3 /usr/local/sbin/mastodon-announce.py /etc/sitepull/mastodon-announce.conf"
If you also run a staging site, make sure that this line does not end up in its configuration, or your test posts will be tooted too. And if you want to see what would happen before you trust the script with your account, run it with --dry-run, or set VISIBILITY=private in its configuration for the first toot.
Check the result
Time to see if everything works together:
- Open https://blog.darkstar.lan/admin/, write a short post with an image, and save it. On the forge you should see a new branch and a pull request, and no build job.
- Publish the post. A build job starts in the Actions tab; when it is finished, a new version of the “blog-production” package appears.
- Within five minutes, your syslog should show sitepull’s “activated” message, and the post is on https://blog.darkstar.lan/.
- If you set up the Mastodon announcement: a toot with a link to the new post appears on your Mastodon account, and /usr/local/blog/mastodon-announce.log has a line with its URL.
- Leave a comment on it from a private browser window, with a name and email address that you have never used. It should wait in the moderation queue, and you should get an email.
- Log in to the Dashboard from the comment box, approve the comment, then post a second comment with the same name and email address. That one should be published within a minute, thanks to the moderation sidecar.
- Search for a word from your post on the search page.
Coming from WordPress?
My own situation was a migration, not a fresh start: more than 900 posts, 757 tags and more than 20,000 comments, written over eighteen years. A few things that helped:
- The export: Tools > Export in WordPress gives you a WXR file (an XML file with all your posts, pages, comments, categories and tags). Mine was 31 MB.
- The conversion: I wrote a Python script that turns the WXR file into Hugo content files. My old posts stay HTML (Hugo can render HTML content files as well as Markdown), so nothing gets lost in a conversion to Markdown. The script also takes care of the WordPress-specific bits like
[caption]shortcodes, the automatic paragraph formatting that WordPress applies when it shows a post, and the output of plugins like “List category posts”. It writes the comments in Artalk’s import format, and turns pingbacks into a static “Mentioned elsewhere” list under each post. I cleaned up the script for general use and published it with step-by-step instructions, including the Hugo templates and Apache redirect rules that go with it: wp2hugo. - The comments: Artalk’s import command reads the converted comments into its database:
docker exec artalk artalk import -y -p '{"target_site_name":"My Blog","target_site_url":"https://blog.darkstar.lan"}' /data/comments.artrans. Your own old comments end up under your admin account if the name and email address in the export match those in the Docker Compose file. - The images: I did not put eighteen years of uploaded images into git. The wp-content/uploads directory was copied once to /usr/local/blog-media/ on the web server, and an Apache
Alias /wp-content/uploadsserves it from there. Only new images, uploaded with Sveltia, live in the git repository. - Old URLs: people and search engines will keep using the old WordPress URLs for years. Apache’s mod_rewrite with a
RewriteMap(generated by the conversion script) sends/?p=1234to the right post,/feed/to the new RSS feed,/2024/01/to the archive page, and answers410 Goneto/wp-login.php,/xmlrpc.phpand friends. A test script that checks every old post ID against the live site gave me confidence on the day of the switch. - Jetpack’s social sharing: the Mastodon announcement described above replaces it. The posts from WordPress are recorded as “seen” on the first run, so switching over does not toot eighteen years of articles. For migrated posts, the theme uses the original image as the preview image, not WordPress’ 150x150 pixel thumbnail.
- Old links to comments: links like
/my-post/#comment-12345are common on forums. Artalk numbers the comments anew during the import, so the conversion script also writes a small “old number to new number” file, and a few lines of JavaScript in the theme translate the old link into Artalk’s own#atk-comment-678.
Lessons learned
Some things that cost me time, so that they don’t have to cost you time:
- Hugo ignores symlinked directories in
static/. Use rsync or a bind mount if you want to include files from elsewhere in a local preview. - Recent Hugo versions refuse to render HTML content files unless you allow it explicitly with
security.allowContentin your configuration. You need this for migrated WordPress posts. - Use
hugo.Datainstead of.Site.Datain your templates; the latter is deprecated. - Copy-pasted text from WordPress is full of invisible no-break spaces (the classic editor turns a double space into one). Forgejo warns about “invisible Unicode characters” in such files. Writing them as
makes them visible and changes nothing in the browser. - In an Apache
RewriteCondlist, every line except the last one before theRewriteRuleneeds[OR]. Forget one, and the conditions are combined with AND, which silently breaks the whole rule.apachectl configtestwill not warn you, because the syntax is valid. - The Artalk Docker image defaults to the Asia/Shanghai timezone. You need to set
ATK_TIMEZONEand not just the container’sTZ.
Attribution
This platform stands on the shoulders of some great Open Source projects: Hugo, Forgejo, Artalk, Sveltia CMS by Kohei Yoshino, and Pagefind by CloudCannon. The look of this blog is still the Hemingway theme by Anders Norén, which I ported to Hugo.
The migration itself was done in a long series of evening sessions with Claude AI as my sparring partner. As I wrote in my post about the Slackware Cloud Server in real life: AI can be an accelerator, as long as the ideas start with you and the quality control ends with you. Every script in this article ran on my own servers before it ended up here.
Final thoughts
I am really pleased with the result. The blog is faster than it ever was, my server has one PHP application less to worry about, and I write my posts in a browser editor that does what I expect from it. And everything, from the text of every post to every comment, lives on servers that I control.
Is this setup more complex than “install WordPress”? At first sight, the answer is “yes, certainly”. But all the moving parts are small, and each of them does one thing. That’s exactly the UNIX philosophy of “do one thing and do it well”! If the forge is down, the blog keeps working. If the runner breaks, I fix it and the next build catches up. If I want to move the blog to another server, I copy one script and one configuration file.
Leave your comments, suggestions and opinions below. They’ll go through the moderation queue of course, unless you have commented here before ;-)
Thanks for reading. Eric
I wanted to share some news with you. After weeks of hard work and being forced to learn new tech from scratch, the Slackware Community Forge, a git software forge, is now available at 



I hope you will appreciate this new service and also start migrating your Github / Gitlab repositories to the Slackware Community Forge.
Someone asked how I am creating Chromium (also -ungoogled) packages these days? When you download my SlackBuild script and attempt to build the package yourself, the script will error out because it cannot download the sources.
Recent comments