blob: 99c0ed4944167a272cf9bda0aac3d1d876caeb07 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
#!/bin/sh
# Build the site into public/: each posts/*.org becomes public/posts/<name>.html
# (via pandoc and template.html), and the newest-first post list replaces the
# <!-- POSTS --> 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; s/>/\>/g')
printf '%s\t<a href="posts/%s.html" class="post-entry"><h2>%s</h2><small>%s</small></a>\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" '
/<!-- POSTS -->/ { while ((getline line < list) > 0) print line; close(list); next }
{ print }
' index.html >"$out/index.html"
rm -rf public
mv "$out" public
|