Skip to content

Commit 6328ee9

Browse files
authored
Migrate tutorials (commontoolsinc#1871)
Migrating tutorials docs repo into the labs repo https://github.com/commontoolsinc/tutorials/tree/main at b8610b29613f251543ab8a37d11c7d68020f41f9 These docs now live at https://docs.commontools.dev
1 parent 374bcb2 commit 6328ee9

37 files changed

+3872
-1
lines changed

.github/workflows/deploy-docs.yml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: Deploy MyST Documentation
2+
3+
on:
4+
push:
5+
branches: [main]
6+
paths:
7+
- "tutorials/**"
8+
- ".github/workflows/deploy-docs.yml"
9+
workflow_dispatch: # Allow manual trigger
10+
11+
env:
12+
# For custom domain docs.commontools.dev, we don't need a subfolder
13+
BASE_URL: ""
14+
15+
permissions:
16+
contents: read
17+
pages: write
18+
id-token: write
19+
20+
concurrency:
21+
group: "pages"
22+
cancel-in-progress: false
23+
24+
jobs:
25+
build:
26+
runs-on: ubuntu-latest
27+
steps:
28+
- name: Checkout
29+
uses: actions/checkout@v4
30+
31+
- name: Setup Node.js
32+
uses: actions/setup-node@v4
33+
with:
34+
node-version: "20"
35+
cache: "npm"
36+
cache-dependency-path: tutorials/package-lock.json
37+
38+
- name: Install dependencies
39+
working-directory: tutorials
40+
run: npm ci
41+
42+
- name: Build MyST site
43+
working-directory: tutorials
44+
run: npm run build
45+
46+
- name: Copy CNAME to build directory
47+
run: cp tutorials/CNAME tutorials/_build/html/CNAME
48+
49+
- name: Upload artifact
50+
uses: actions/upload-pages-artifact@v3
51+
with:
52+
path: "tutorials/_build/html"
53+
54+
deploy:
55+
# Only deploy from main branch
56+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
57+
environment:
58+
name: github-pages
59+
url: ${{ steps.deployment.outputs.page_url }}
60+
runs-on: ubuntu-latest
61+
needs: build
62+
steps:
63+
- name: Deploy to GitHub Pages
64+
id: deployment
65+
uses: actions/deploy-pages@v4

CNAME

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
docs.commontools.dev

deno.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@
9191
"packages/static/assets/",
9292
"packages/ts-transformers/test/fixtures",
9393
"packages/schema-generator/test/fixtures",
94-
"packages/vendor-astral"
94+
"packages/vendor-astral",
95+
"tutorials/"
9596
]
9697
},
9798
"imports": {

tutorials/.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Node / tooling
2+
node_modules/
3+
npm-debug.log*
4+
5+
# Myst build output
6+
_build/
7+
.cache/

tutorials/.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
18

tutorials/CNAME

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
docs.commontools.dev

tutorials/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Tutorials
2+
3+
Install MyST Markdown tooling by following https://mystmd.org/guide/installing. Once set up, run `myst` in this directory to serve the tutorial pages locally.
4+
5+
## npm quickstart
6+
7+
```sh
8+
npm i
9+
npm run dev
10+
```
11+
12+
TODO:
13+
* Add document on how Input and Output schemas work for Recipes
14+
* Chapter on basic UI and existing ct components

tutorials/README_BUILD.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Documentation Build Process
2+
3+
This directory contains the MyST documentation that gets built and deployed to https://docs.commontools.dev
4+
5+
## Overview
6+
7+
While the main codebase uses Deno, the documentation is built using MyST (mystmd), which is a Node.js-based static site generator for scientific and technical documentation.
8+
9+
## GitHub Actions Deployment
10+
11+
The documentation is automatically built and deployed via GitHub Actions when:
12+
- Changes are pushed to the `main` branch
13+
- The changes affect files in the `tutorials/` directory
14+
- Or when manually triggered via workflow dispatch
15+
16+
The workflow is defined in `.github/workflows/deploy-docs.yml`
17+
18+
## Local Development
19+
20+
To work on the documentation locally, you'll need Node.js (not Deno) for MyST:
21+
22+
```bash
23+
# Navigate to tutorials directory
24+
cd tutorials
25+
26+
# Install dependencies (requires Node.js)
27+
npm install
28+
29+
# Start development server
30+
npm run dev
31+
32+
# Build static site
33+
npm run build
34+
```
35+
36+
## Configuration
37+
38+
- **MyST Config**: `myst.yml` - Defines the site structure and settings
39+
- **Custom Domain**: The CNAME file configures the custom domain (docs.commontools.dev)
40+
- **GitHub Pages**: The site is deployed to GitHub Pages with the custom domain
41+
42+
## Important Notes
43+
44+
1. The MyST build process is completely separate from the Deno-based application code
45+
2. The GitHub Action uses Node.js to build the documentation
46+
3. The built HTML is deployed to GitHub Pages
47+
4. Make sure to configure DNS records to point `docs.commontools.dev` to GitHub Pages
48+
49+
## DNS Configuration Required
50+
51+
For the custom domain to work, you need to configure DNS:
52+
- Add a CNAME record pointing `docs.commontools.dev` to `<username>.github.io`
53+
- Or configure it according to GitHub's custom domain documentation

tutorials/code/state_02.tsx

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/// <cts-enable />
2+
import {
3+
cell,
4+
h,
5+
recipe,
6+
UI,
7+
lift,
8+
derive,
9+
handler,
10+
type Cell,
11+
} from "commontools";
12+
13+
const calcAC = (dex: number) : number =>
14+
20 + Math.floor((dex - 10) / 2);
15+
16+
const updateName = handler<
17+
{ detail: { message: string } },
18+
{ characterName: Cell<string> }
19+
>(
20+
(event, { characterName }) => {
21+
console.log("Updating character name to:", event.detail.message);
22+
characterName.set(event.detail.message);
23+
}
24+
);
25+
26+
export default recipe("state test", () => {
27+
const characterName = cell<string>("");
28+
characterName.set("Lady Ellyxir");
29+
const dex = cell<number>(16);
30+
const ac = lift(calcAC)(dex);
31+
32+
return {
33+
[UI]: (
34+
<div>
35+
<h2>Character name: {characterName}</h2>
36+
<common-send-message
37+
name="Update"
38+
placeholder="Update Name"
39+
onmessagesend={updateName({ characterName })}
40+
/>
41+
<li>DEX: {dex}</li>
42+
<li>DEX Modifier: {Math.floor((dex - 10) / 2)}</li>
43+
<li>AC: {ac}</li>
44+
</div>
45+
),
46+
};
47+
});

tutorials/code/state_03.tsx

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/// <cts-enable />
2+
import {
3+
cell,
4+
h,
5+
recipe,
6+
UI,
7+
lift,
8+
derive,
9+
handler,
10+
type Cell,
11+
} from "commontools";
12+
13+
const calcAC = (dex: number) : number =>
14+
20 + Math.floor((dex - 10) / 2);
15+
16+
const updateName = handler<
17+
{ detail: { message: string } },
18+
{ characterName: Cell<string> }
19+
>(
20+
(event, { characterName }) => {
21+
characterName.set(event.detail.message);
22+
}
23+
);
24+
25+
const rollD6 = () => Math.floor(Math.random() * 6) + 1;
26+
27+
const rollDex = handler<
28+
unknown,
29+
Cell<number>
30+
>(
31+
(_, dex) => {
32+
// Roll 3d6 for new DEX value
33+
const roll = rollD6() + rollD6() + rollD6();
34+
dex.set(roll);
35+
}
36+
);
37+
38+
export default recipe("state test", () => {
39+
const characterName = cell<string>("");
40+
characterName.set("Lady Ellyxir");
41+
const dex = cell<number>(16);
42+
const ac = lift(calcAC)(dex);
43+
44+
return {
45+
[UI]: (
46+
<div>
47+
<h2>Character name: {characterName}</h2>
48+
<common-send-message
49+
name="Update"
50+
placeholder="Update Name"
51+
onmessagesend={updateName({ characterName })}
52+
/>
53+
<li>
54+
DEX: {dex}
55+
{" "}
56+
<ct-button onClick={rollDex(dex)}>
57+
Roll
58+
</ct-button>
59+
</li>
60+
<li>DEX Modifier: {Math.floor((dex - 10) / 2)}</li>
61+
<li>AC: {ac}</li>
62+
</div>
63+
),
64+
};
65+
});

0 commit comments

Comments
 (0)