Neko

Made With

Last modified: 2026.07.29


This site is built ENTIRELY on a set of good tools:

The entire makefile looks like this:

all:
    ./build.sh

clean:
    rm -rf html

.PHONY: all clean

build.sh looks like this:

#!/bin/sh
set -eu

SRC_DIR=src
OUT_DIR=html
TPL=template.html
PANDOC=${PANDOC:-pandoc}

build_page() {
    src=$1
    out=$2

    printf 'build: %s\n' "$out"

    mkdir -p "$(dirname "$out")"

    title=$(
        head -n 5 "$src" |
        sed -n 's/^title:[[:space:]]*//p' |
        head -n1
    )

    [ -n "$title" ] || title=$(basename "$src" .md)

    lastmod=$(stat -f '%Sm' -t '%Y.%m.%d' "$src")

    tmp=$(mktemp)

    trap 'rm -f "$tmp"' EXIT HUP INT TERM

    "$PANDOC" -f markdown -t html "$src" >"$tmp"

    awk \
        -v title="$title" \
        -v lastmod="$lastmod" \
        -v article="$tmp" '
BEGIN {
    while ((getline line < article) > 0)
        body = body line "\n"
    close(article)
}
{
    gsub(/@@=TITLE=@@/, title)
    gsub(/@@=LAST_MOD=@@/, lastmod)

    if ($0 ~ /@@=ARTICLE=@@/) {
        printf "%s", body
        next
    }

    print
}
' "$TPL" >"$out"

    rm -f "$tmp"
    trap - EXIT HUP INT TERM
}

copy_static() {
    src=$1
    rel=${src#static/}
    dst="$OUT_DIR/$rel"

    mkdir -p "$(dirname "$dst")"

    if [ ! -e "$dst" ] || [ "$src" -nt "$dst" ]; then
        printf 'copy: %s\n' "$src"
        cp "$src" "$dst"
    fi
}

mkdir -p "$OUT_DIR"

find static -type f | while IFS= read -r f; do
    copy_static "$f"
done

find "$SRC_DIR" -type f -name '*.md' | while IFS= read -r src; do
    rel=${src#"$SRC_DIR"/}
    out=$OUT_DIR/${rel%.md}.html

    if [ ! -f "$out" ] ||
       [ "$src" -nt "$out" ] ||
       [ "$TPL" -nt "$out" ]; then
        build_page "$src" "$out"
    fi
done