aboutsummaryrefslogtreecommitdiffstats
path: root/web/build-site
blob: e5766f90d9537e382266465430e24a6f6f2d77ec (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/sh
# Assemble the whole website into build/www:
#
#     /            web/             the front page (this directory)
#     /docs/       contrib/gen-docs the rendered documentation
#     /demo/       web/demo/        the in-browser machine, on its own page
#
#     web/build-site               everything (or: make www)
#     NO_DEMO=1 web/build-site     skip the demo (it cross-compiles a
#                                  guest and needs zig + e2fsprogs)
#
# The output is only static files. Serve it with anything that serves a
# directory; the one condition is .wasm as application/wasm, which
# `web/demo/serve --dir build/www` handles locally.

set -eu

here="$(cd "$(dirname "$0")" && pwd)"
root="$(dirname "$here")"
www="$root/build/www"

# Assemble into a staging directory and swap at the end: a build that fails
# halfway (set -eu) must not have already deleted the site that worked.
out="$root/build/.www-staging"
rm -rf "$out"
mkdir -p "$out"

publish() {
    rm -rf "$www"
    mv "$out" "$www"
}

# The front page. Its recordings are below; there is no video. The released
# version is stamped in from ./VERSION: the file the release invariant keeps
# equal to the newest tag, so the page cannot claim a version that was never
# cut, and a snapshot without git still knows the answer.
sed "s/@VERSION@/v$(cat "$root/VERSION")/g" "$here/index.html" > "$out/index.html"
cp "$here/site.css" "$out/"

# The social-embed card (og:image / twitter:image). Rendered by hand with
# web/gen-card when logo.txt or the palette changes, committed, and only
# copied here -- regenerating would make Pillow a build dependency.
cp "$here/card.png" "$out/"

# The docs, rendered by the same generator `make docs` uses.
python3 "$root/contrib/gen-docs" "$out/docs"

# The recordings: scripted feature playbacks (see recordings/PLAN.md),
# re-rendered from their driver scripts so they can never be stale.
make -C "$here/recordings"
mkdir -p "$out/recordings"
cp "$here/recordings/build/"*.json \
   "$here/recordings/player.js" "$here/recordings/player.css" \
   "$out/recordings/"

# The demo, assembled by its own Makefile, on its own page.
if [ "${NO_DEMO:-0}" = 1 ]; then
    echo "build-site: skipping demo (NO_DEMO=1)"
else
    make -C "$here/demo" site
    mkdir -p "$out/demo"
    cp -R "$here/demo/build/site/." "$out/demo/"
fi

publish
echo "build-site: $www"
echo "build-site: serve with: web/demo/serve --dir build/www"