Migrating to Nikola

I've written my last posting on this blog more than 5 years ago. When I recently wanted to share some details of my backup system with you, I noticed that tinkerer, the blog compiler I've been using previously did not receive any updates since 2017 and won't run flawlessly on my system any more. So, once again I had to migrate the old blog posts to a new system: Nikola. This time however, the migration was easier than the previous time as tinkerer's blog posts are stored as reStructuredText - a format supported by Nikola as well. All I had to do was to create a small script that creates *.rst files containing the appropriate headers for Nikola, especially the title, slug and date:

#!/bin/bash
FILE=$1
if [[ ! $FILE =~ 2[0-9][0-9][0-9]/[0-9][0-9]/[0-9][0-9] ]]; then
        echo "file path must include the date!"
        exit 1;
fi
DATE=$(egrep -o "2[0-9][0-9][0-9]/[0-9][0-9]/[0-9][0-9]" <<< "$FILE")
YY=$(cut -d '/' -f 1 <<< "$DATE")
MM=$(cut -d '/' -f 2 <<< "$DATE")
DD=$(cut -d '/' -f 3 <<< "$DATE")


TITLE=$(head -1 "$1")
SLUG=$(tr '[:upper:]' '[:lower:]' <<< "$TITLE" | sed 's#[^0-9a-z]#_#g')
CATEGORIES=$(grep ".. categories::" "$1" |  cut -d ":" -f 3-)
TAGS=$(grep ".. tags::" "$1" |  cut -d ":" -f 3-)
LINES=$(wc -l "$1"  | awk '{print $1}')
LINES=$((LINES-2))

echo ".. title: $TITLE"
echo ".. slug: $SLUG"
echo ".. date: $YY-$MM-$DD 12:00:00 UTC+02:00"
echo ".. tags: $TAGS"
echo ".. category: $CATEGORIES"
echo ".. link: "
echo ".. description: "
echo ".. type: text"


tail -n "$LINES" "$FILE" | egrep -v "\.\. author::|\.\. categories::|\.\. tags::|\.\. comments::|\.\ highlight:: none" | sed 's#.. [h|H]ighlight::#.. code-block::#g'

Because tinkerer stored the date of the blog posting via the directory structure, the script needs this information as well:

find . -name "*rst" | grep ./2 | while read l; do ./script.sh "$l" > "~/blog/posts/$(basename "$l")"; done

Unfortunately, back in 2013/2014, I did some strange things in the original *.rst files, so I had to fix several files manually. Nevertheless, the script shown above saved me lots of work.