build.sh
27 lines · 1042 bytes · executable
1#!/usr/bin/env bash
2# Build the site into public/ with orgo, then do what orgo does not: version asset
3# URLs by content hash, set the footer year, and list directory URLs in the sitemap.
4set -euo pipefail
5cd "$(dirname "$0")"
6
7rm -rf public
8orgo build content -o public --strict
9
10# Cloudflare caches assets for a year, so each URL changes when its file does.
11for f in main.css favicon.svg apple-touch-icon.png og.png; do
12 h=$(shasum -a 256 "public/$f" | cut -c1-20)
13 find public -name '*.html' -exec perl -pi -e "s{/\\Q$f\\E\"}{/$f?h=$h\"}g" {} +
14 if ! grep -rqF "$f?h=$h" public --include='*.html'; then
15 echo "build.sh: no links to $f found; templates/base.html changed?" >&2
16 exit 1
17 fi
18done
19
20year=$(date +%Y)
21find public -name '*.html' -exec perl -pi -e "s{© \\d{4} ·}{© $year ·}g" {} +
22
23# orgo lists directory indexes by file; the site links them as /dir/.
24perl -pi -e 's{/index\.html</loc>}{/</loc>}g' public/sitemap.xml
25
26# The incremental cache is a build input, not part of the site.
27rm public/.orgo-cache.json