kevin's website

Rebuilding My Site As a Wiki

Kevin Nel

I've been very interested in the concepts of digital gardens and personal knowledge management systems, so i decided to try and build my own system that could help me be a little more productive when it comes to writing articles, completing projects and organizing information.

This post is a little bit more technical.

pandoc as a static site generator

I wanted something simple and I really didn't want to mess with jekyll again so i decided to make a little wrapper script for pandoc.

It takes in a folder full of markdown files that link each other where all the assests are in an assets folder. and converts it into a website with common header and footer.

the site directory should look as follows

.
├── pkms-site/
│   ├── assets/
│   ├── blog/
│   ├── notes/
│   ├── projects/
│   └── index.md
└── site/
    ├── footer.html
    ├── header.html
    ├── links-to-html.lua
    └── md-pan-wiki.sh

md-pan-wiki.sh contains the following.

#! /bin/bash

# run in /site directory
# this copies the directory structure into ./export/ without copying the files
cd ../pkms-site;
find ./ -type d > ../site/dirs.txt;
cd ../site;
mkdir -p export;
cd export;
xargs mkdir -p < ../dirs.txt;
# this copies assests like images into the new export assests directory
cp -r ../../pkms-site/assets/* assets/ ;

# find all md files and feed them in to pandoc as input files.
cd ../../pkms-site;

find ./ -iname "*.md" -type f -exec sh -c 'pandoc -f markdown+tex_math_dollars-smart -t html5 "${0}" -so "../site/export/${0%.*}.html" --lua-filter=../site/links-to-html.lua --include-after-body=../site/footer.html --include-before-body=../site/header.html --css /assets/css/oldschool.css --html-q-tags --katex --no-highlight' {} \;
# ${0%.*} strips the file extension while leaving the path
# the lua filter converts all relative links to .md files to .html files

links-to-html.lua is a lua filter that changes all the relative links to .md files into links to .html files

function Link(el)
    el.target = string.gsub(el.target, "%.md", ".html")
    return el
end