Skip to main content

Nikola

Nikola

This post is long overdue. After this domain moved to a different provider, I decided that Serendipity served me well enough for a long time but I no longer had the need for a dynamic site and wanted to switch to a static site instead. Nikola appeared to be the best fit for my needs and also was able to convert the S9Y blog into static pages.

Export the S9Y blog via its RSS feed:

$ wget "http://nerdbynature.local/s9y/rss.php?version=2.0&all=1" -O index.rss
$ ls -hgo index.rss
-rw-r----- 1 1.2M Aug  4 02:30 index.rss


Install Nikola via venv:

sudo apt-get install python3-venv
python3 -m venv opt/nikola
cd opt/nikola/
source bin/activate
bin/python -m pip install -U pip setuptools wheel
bin/python -m pip install -U "Nikola[extras]"


We don't even need the exported .rss file from before, we can import on-the-fly:

$ nikola plugin -i import_feed
$ nikola import_feed --output-folder=www/s9y \
    --url="http://nerdbynature.local/s9y/rss.php?version=2.0&all=1"


With all that in place, we're amost ready to go. Let's install a theme, build our site and serve it:

$ cd www/s9y/
$ nikola theme -i lanyon
$ nikola build && nikola serve


Be sure to tweak conf.py as needed (see below).

That was all fine and dandy, but all the (newly imported) posts were named a bit funny:

$ ls posts/
s9y20061006debianunstable-and-apache22.html
s9y20061119benchmarks-2619-rc5-git4.html
s9y20061205testing-mm-playing-around-with-xfs.html
[...]


While new posts could be created with NEW_POST_DATE_PATH=true set, I really wanted my old posts to be accessible via posts/%year/%month/%day/%title. Some ugly lines of shell later, this did the trick:

set -e
for p in $(ls posts/s9y*html); do
    DATE="$(date +%Y/%m/%d -d $(echo "$p" | sed 's|posts/s9y||' | cut -c-8))"
    NAME="$(echo $p | cut -c18- | sed 's/\.html$//')"
    mkdir -p            posts/${DATE}
    mv ${p}             posts/${DATE}/${NAME}.html
    mv ${p%%.html}.meta posts/${DATE}/${NAME}.meta
    sed "s|slug: .*|slug: ${NAME}|" -i posts/${DATE}/${NAME}.meta
    echo
done


After some cosmetic changes the (imported) blog was ready to be deployed into the webserver's document root:

$ nikola build && nikola deploy


And that's it! Goodbye S9Y, hello Nikola :-D

conf.py

$ cat conf.py
[...]
BLOG_TITLE = "nerdbynature"
SITE_URL = "https://nerdbynature.de/s9y/"
BASE_URL = "https://nerdbynature.de/s9y/"
BLOG_EMAIL = "admin@example.com"
BLOG_DESCRIPTION = "Who took the 'we' out of weblog?"

NAVIGATION_LINKS = {
     DEFAULT_LANG: (
       ("/archive.html", "Archives"),
       ("/categories/index.html", "Tags"),
       ("/rss.xml", "RSS feed"),
       ("/feed.atom", "Atom feed"),
       ("/imprint.html", "Imprint"),
     ),
}

THEME    = "lanyon"
TIMEZONE = "SystemV/PST8PDT"
DATE_FANCINESS = 0
GENERATE_RSS   = True
GENERATE_ATOM  = True
FEED_LENGTH    = 10000
USE_CDN        = False

POSTS = (
       ("posts/*.html", "posts", "post.tmpl"),
       ("posts/*.md",   "posts", "post.tmpl"),
)

COMPILERS = {
        "rest": ('.txt', '.rst'),
        "markdown": ('.md', '.mdown', '.markdown', '.wp'),
        "html": ('.html', '.htm')
}

DEPLOY_COMMANDS = {
    'default': [
       "rsync -av --delete output/ admin@webserver:/var/www/",
#      "tar -czf /tmp/s9y.tar.gz output/"
    ]
}