Skip to content

Commit 7fa7a06

Browse files
committed
build: add make build-serve for local preview
- Document build/preview process in README - Document ADRs in README - add small threaded server to scripts/serve.py Assisted-by: claude-code:claude-opus-4-8
1 parent 7588ac2 commit 7fa7a06

3 files changed

Lines changed: 78 additions & 1 deletion

File tree

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: help prepare cookie external html serve clean
1+
.PHONY: help prepare cookie external html serve build-serve clean
22
.DEFAULT_GOAL := help
33

44
# Add help text after each target name starting with '\#\#'
@@ -31,6 +31,10 @@ serve: ## Serve site, typically on http://localhost:3000
3131
serve: prepare
3232
(cd content && myst start)
3333

34+
build-serve: ## Build full site (learn + cookie) and serve `./public` at http://localhost:3000
35+
build-serve: html-all
36+
python3 scripts/serve.py 3000 public
37+
3438
clean: ## Remove built files
3539
clean:
3640
rm -rf content/_build public

README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,43 @@
11
# learn.scientific-python.org
2+
3+
Source for [learn.scientific-python.org](https://learn.scientific-python.org),
4+
built with [MyST-MD](https://mystmd.org/) (the `mystmd` CLI).
5+
6+
## Layout
7+
8+
- `content/` — the MyST source project (`myst.yml` lives here). This is the
9+
main site.
10+
- `external-content/cookie/` — the [cookie](https://github.com/scientific-python/cookie)
11+
submodule, a separate MyST site. Its build is overlaid at `/development/`.
12+
- `public/` — build output. The merged, deployable static site (main +
13+
cookie). Written by `make html-all`; published by Netlify.
14+
15+
## Prerequisites
16+
17+
- **mystmd** — the `myst` CLI. See the
18+
[MyST install guide](https://mystmd.org/guide/quickstart).
19+
- **Node** — the cookie overlay builds via `npx mystmd`, so a full build needs
20+
Node available.
21+
- **git** — the cookie content is a submodule; `make prepare` initializes it.
22+
23+
## Local development
24+
25+
| Command | What it does |
26+
| ------------------ | ----------------------------------------------------------------------- |
27+
| `make serve` | Live-reload dev server for the **main site only**, at `localhost:3000`. |
28+
| `make html` | Build the main site to `content/_build/html/`. |
29+
| `make html-all` | Build main + cookie, merged into `public/`. |
30+
| `make build-serve` | Run `html-all`, then serve the full merged site at `localhost:3000`. |
31+
| `make clean` | Remove build output (`content/_build`, `public/`). |
32+
33+
**Previewing `/development/` (cookie) locally:** `make serve` (and `myst start`)
34+
serve `content/` only — the cookie overlay is **not** visible there. To preview
35+
the full site, including `/development/`, use `make build-serve`. It is a static
36+
build (no live reload); rerun it after edits.
37+
38+
## Decisions
39+
40+
Architecture decisions are recorded in
41+
[`docs/decisions/`](docs/decisions/). See
42+
[`0001-myst-migration/`](docs/decisions/0001-myst-migration/) for the
43+
Hugo → MyST migration.

scripts/serve.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env python3
2+
3+
# See https://github.com/Nakiami/MultithreadedSimpleHTTPServer/blob/master/MultithreadedSimpleHTTPServer.py
4+
5+
# Python 3.x
6+
import sys
7+
import os
8+
9+
from socketserver import ThreadingMixIn
10+
from http.server import SimpleHTTPRequestHandler, HTTPServer
11+
12+
13+
class ThreadingSimpleServer(ThreadingMixIn, HTTPServer):
14+
pass
15+
16+
17+
if sys.argv[1:]:
18+
port = int(sys.argv[1])
19+
else:
20+
port = 8000
21+
22+
if sys.argv[2:]:
23+
os.chdir(sys.argv[2])
24+
25+
server = ThreadingSimpleServer(("", port), SimpleHTTPRequestHandler)
26+
server.daemon_threads = True
27+
print(f"Starting server on 0.0.0.0:{port}")
28+
try:
29+
server.serve_forever()
30+
except KeyboardInterrupt:
31+
print("Finished")

0 commit comments

Comments
 (0)