A fork of mtelver's day10 project
1#!/bin/bash
2# Build and optionally serve the full jon.recoil.org site.
3#
4# The site is built in two passes:
5# 1. `dune build @site` — site content (.mld pages → HTML)
6# Output: _build/default/site/_html/
7# 2. `dune build @doc` — reference docs (library API docs)
8# Output: _build/default/_doc/_html/reference/
9#
10# These are combined into a single tree for serving/deployment:
11# _build/default/site/_html/ — site root
12# _build/default/site/_html/reference/ — symlinked to @doc output
13#
14# Prerequisites:
15# - opam switch "default" with dune 3.21+ (html_flags + prefix support)
16# - odoc-jons-plugins and odoc-interactive-extension in the workspace
17#
18# Usage:
19# ./deploy-site.sh # build everything and serve on port 8080
20# ./deploy-site.sh --no-serve # build only
21
22set -euo pipefail
23
24MONO=$(cd "$(dirname "$0")" && pwd)
25SITE_HTML="$MONO/_build/default/site/_html"
26DOC_HTML="$MONO/_build/default/_doc/_html"
27SERVE=true
28
29if [[ "${1:-}" == "--no-serve" ]]; then
30 SERVE=false
31fi
32
33# Ensure we're on the right switch.
34export OPAMSWITCH=default
35eval "$(opam env)"
36
37echo "=== Step 1: Build and register plugins ==="
38cd "$MONO"
39dune build @install
40# Shell and extensions must be findlib-visible for odoc to load them.
41# x-ocaml.js is found from _build/install/ so x-ocaml itself doesn't need installing.
42dune install odoc-jons-plugins odoc-interactive-extension odoc-scrollycode-extension 2>/dev/null
43echo " plugins registered"
44
45echo ""
46echo "=== Step 2: Build site content ==="
47dune build @site 2>&1 | grep -v '^Warning\|^File\|^$' | tail -5 || true
48echo " site built → $SITE_HTML/"
49
50echo ""
51echo "=== Step 3: Build universes for interactive code cells ==="
52jtw opam astring brr note mime_printer fpath rresult \
53 opam-format bos odoc.model tyxml yojson uri jsonm \
54 js_top_worker-widget-leaflet \
55 tessera-geotessera-jsoo tessera-viz-jsoo -o "$SITE_HTML/_opam"
56echo " universe built → $SITE_HTML/_opam/"
57
58echo ""
59echo "=== Step 4: Build reference docs ==="
60dune build @doc 2>&1 | tail -5 || true
61echo " reference docs built → $DOC_HTML/reference/"
62
63echo ""
64echo "=== Step 5: Merge reference docs into site ==="
65# Copy @doc reference output into the site's reference/ directory.
66# The site build already creates reference/index.html from reference/index.mld;
67# we add the API docs packages alongside it.
68# Make existing files writable first (dune marks build outputs read-only).
69chmod -R u+w "$SITE_HTML/reference/" "$SITE_HTML/odoc.support/" 2>/dev/null || true
70cp -rf "$DOC_HTML/reference/"* "$SITE_HTML/reference/"
71mkdir -p "$SITE_HTML/odoc.support/"
72cp -rf "$DOC_HTML/odoc.support/"* "$SITE_HTML/odoc.support/"
73echo " merged reference docs into site tree"
74
75echo ""
76echo "=== Done ==="
77echo ""
78echo "Site root: $SITE_HTML/"
79echo ""
80echo "Key pages:"
81echo " /index.html — site home"
82echo " /blog/index.html — blog index"
83echo " /notebooks/index.html — notebooks index"
84echo " /notebooks/foundations/index.html — foundations of CS"
85echo " /projects/index.html — projects"
86echo " /reference/ — API reference docs"
87
88if $SERVE; then
89 echo ""
90 echo "Starting HTTP server on http://localhost:8080"
91 cd "$SITE_HTML"
92 exec python3 -m http.server 8080
93fi