#!/bin/sh # Build the site into public/: each posts/*.org becomes public/posts/.html # (via pandoc and template.html), and the newest-first post list replaces the # markers in index.html. Posts need #+TITLE and #+DATE: YYYY-MM-DD. # Builds into public.tmp/ and swaps it in at the end, so a failed build keeps the old site. set -eu cd "$(dirname "$0")" out=public.tmp rm -rf "$out" mkdir -p "$out/posts" cp style.css "$out/" list=$(mktemp) sorted=$(mktemp) trap 'rm -f "$list" "$sorted"' EXIT for f in posts/*.org; do [ -e "$f" ] || continue name=$(basename "$f" .org) title=$(sed -n 's/^#+title:[[:space:]]*//Ip' "$f" | head -n 1) [ -n "$title" ] || title=$name date=$(sed -n 's/^#+date:[[:space:]]*//Ip' "$f" | grep -o '[0-9]\{4\}-[0-9][0-9]-[0-9][0-9]' | head -n 1) pandoc -f org -t html5 --template template.html --syntax-highlighting=none \ -M title="$title" -M date="$date" -o "$out/posts/$name.html" "$f" html_title=$(printf '%s' "$title" | sed 's/&/\&/g; s//\>/g') printf '%s\t

%s

%s
\n' \ "$date" "$name" "$html_title" "$date" >>"$list" done if [ -s "$list" ]; then sort -r "$list" | cut -f 2- >"$sorted" else echo 'No stories to tell...' >"$sorted" fi awk -v list="$sorted" ' // { while ((getline line < list) > 0) print line; close(list); next } { print } ' index.html >"$out/index.html" rm -rf public mv "$out" public