Skip to content

Commit ae42bb4

Browse files
Update docs to experiment with code
1 parent d9fc889 commit ae42bb4

5 files changed

Lines changed: 801 additions & 0 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
# Deploy multilingual docs to GitHub Pages.
2+
#
3+
# This workflow replaces GitHub's default Jekyll deployment so we can:
4+
# 1. Build the multilingual WASM browser bundle from source.
5+
# 2. Copy the resulting .wasm + JS glue into assets/wasm/.
6+
# 3. Build the Jekyll site with the bundled artifacts in place.
7+
# 4. Deploy _site/ to GitHub Pages.
8+
#
9+
# Trigger: every push to main, or manually via workflow_dispatch.
10+
11+
name: Build and deploy docs
12+
13+
on:
14+
push:
15+
branches: [main]
16+
workflow_dispatch:
17+
18+
# Required for the deploy-pages action.
19+
permissions:
20+
contents: read
21+
pages: write
22+
id-token: write
23+
24+
# Cancel in-progress runs on the same branch so pushes don't queue up.
25+
concurrency:
26+
group: pages-${{ github.ref }}
27+
cancel-in-progress: true
28+
29+
jobs:
30+
# ── Job 1: Build WASM ────────────────────────────────────────────────────
31+
build-wasm:
32+
name: Build WASM browser bundle
33+
runs-on: ubuntu-latest
34+
35+
steps:
36+
- name: Checkout multilingual source
37+
uses: actions/checkout@v4
38+
with:
39+
repository: johnsamuelwrites/multilingual
40+
path: multilingual-src
41+
42+
- name: Set up Rust toolchain
43+
uses: dtolnay/rust-toolchain@stable
44+
with:
45+
targets: wasm32-unknown-unknown
46+
47+
- name: Cache Rust build artefacts
48+
uses: actions/cache@v4
49+
with:
50+
path: |
51+
~/.cargo/registry
52+
~/.cargo/git
53+
multilingual-src/target
54+
key: ${{ runner.os }}-cargo-${{ hashFiles('multilingual-src/**/Cargo.lock') }}
55+
restore-keys: ${{ runner.os }}-cargo-
56+
57+
- name: Install wasm-pack
58+
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
59+
60+
- name: Build WASM browser package
61+
working-directory: multilingual-src
62+
run: |
63+
# build_wasm.sh produces wasm/pkg/ with multilingual.js +
64+
# multilingual_bg.wasm (wasm-pack / wasm-bindgen output).
65+
# Fall back to wasm-pack directly if the script is absent.
66+
if [ -f build_wasm.sh ]; then
67+
bash build_wasm.sh --target web
68+
else
69+
wasm-pack build --target web --out-dir wasm/pkg \
70+
--out-name multilingual
71+
fi
72+
73+
# Install the WebAssembly Binary Toolkit so we can generate the WAT
74+
# (text format) alongside the binary for display in the docs.
75+
- name: Install wabt (wasm2wat)
76+
run: |
77+
sudo apt-get install -y wabt
78+
79+
- name: Generate WAT text format
80+
working-directory: multilingual-src/wasm/pkg
81+
run: |
82+
# Convert every .wasm binary to its human-readable .wat counterpart.
83+
for f in *.wasm; do
84+
wasm2wat "$f" -o "${f%.wasm}.wat" || true
85+
done
86+
87+
- name: Upload WASM artefacts
88+
uses: actions/upload-artifact@v4
89+
with:
90+
name: wasm-pkg
91+
# Includes both .wasm binaries and .wat text files.
92+
path: multilingual-src/wasm/pkg/
93+
retention-days: 1
94+
95+
# ── Job 2: Build Jekyll ───────────────────────────────────────────────────
96+
build-jekyll:
97+
name: Build Jekyll site
98+
runs-on: ubuntu-latest
99+
needs: build-wasm
100+
101+
steps:
102+
- name: Checkout docs repo
103+
uses: actions/checkout@v4
104+
105+
- name: Download WASM artefacts
106+
uses: actions/download-artifact@v4
107+
with:
108+
name: wasm-pkg
109+
path: assets/wasm/
110+
111+
- name: Set up Ruby
112+
uses: ruby/setup-ruby@v1
113+
with:
114+
ruby-version: '3.3'
115+
bundler-cache: true # runs `bundle install` and caches gems
116+
117+
- name: Configure GitHub Pages
118+
id: pages
119+
uses: actions/configure-pages@v5
120+
121+
# Jekyll is built with JEKYLL_ENV=production so jekyll-seo-tag,
122+
# jekyll-sitemap, etc. output canonical URLs correctly.
123+
- name: Build Jekyll site
124+
env:
125+
JEKYLL_ENV: production
126+
run: bundle exec jekyll build --baseurl "${{ steps.pages.outputs.base_path }}"
127+
128+
- name: Upload Pages artefact
129+
uses: actions/upload-pages-artifact@v3
130+
with:
131+
path: _site/
132+
133+
# ── Job 3: Deploy ─────────────────────────────────────────────────────────
134+
deploy:
135+
name: Deploy to GitHub Pages
136+
runs-on: ubuntu-latest
137+
needs: build-jekyll
138+
139+
environment:
140+
name: github-pages
141+
url: ${{ steps.deploy.outputs.page_url }}
142+
143+
steps:
144+
- name: Deploy to GitHub Pages
145+
id: deploy
146+
uses: actions/deploy-pages@v4

_layouts/default.html

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<meta charset="UTF-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
66
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
7+
<meta name="base-url" content="{{ site.baseurl }}" />
78
<title>{% if page.title %}{{ page.title }} &mdash; {% endif %}{{ site.title }}</title>
89
<meta name="description" content="{% if page.description %}{{ page.description }}{% else %}{{ site.description }}{% endif %}" />
910

@@ -24,6 +25,9 @@
2425
<meta name="theme-color" content="#080718" />
2526

2627
{% seo %}
28+
29+
<!-- Cross-origin isolation for WASM SharedArrayBuffer support -->
30+
<script src="{{ '/assets/js/coi-serviceworker.js' | relative_url }}"></script>
2731
</head>
2832
<body>
2933
<!-- Background grid -->
@@ -117,6 +121,41 @@ <h4>Project</h4>
117121
</div>
118122
</footer>
119123

124+
<!-- Interactive WASM REPL panel -->
125+
<div class="repl-panel" id="repl-panel" hidden aria-label="Interactive REPL">
126+
<div class="repl-header">
127+
<span class="repl-title">
128+
<span class="repl-status-dot" id="repl-status-dot" data-state="idle"></span>
129+
multilingual REPL
130+
<span class="repl-badge" id="repl-badge">loading…</span>
131+
</span>
132+
<div class="repl-actions">
133+
<button type="button" class="repl-btn" id="repl-run-btn">Run</button>
134+
<button type="button" class="repl-btn repl-btn-ghost" id="repl-wat-btn" title="Show compiled WebAssembly text format">WAT</button>
135+
<button type="button" class="repl-btn repl-btn-ghost" id="repl-clear-btn">Clear</button>
136+
<button type="button" class="repl-btn repl-btn-ghost repl-close-btn" id="repl-close-btn" aria-label="Close REPL">&times;</button>
137+
</div>
138+
</div>
139+
<div class="repl-body">
140+
<textarea class="repl-input" id="repl-input" rows="4"
141+
placeholder="Type multilingual code here…"
142+
spellcheck="false" autocomplete="off" autocorrect="off"></textarea>
143+
<div class="repl-output" id="repl-output" aria-live="polite">
144+
<span class="repl-output-placeholder">Output will appear here</span>
145+
</div>
146+
</div>
147+
</div>
148+
149+
<button type="button" class="repl-toggle" id="repl-toggle"
150+
aria-label="Open interactive REPL" aria-expanded="false" aria-controls="repl-panel">
151+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
152+
width="16" height="16" aria-hidden="true">
153+
<polyline points="4 17 10 11 4 5"></polyline>
154+
<line x1="12" y1="19" x2="20" y2="19"></line>
155+
</svg>
156+
Try it
157+
</button>
158+
120159
<script src="{{ '/assets/js/main.js' | relative_url }}"></script>
121160
</body>
122161
</html>

0 commit comments

Comments
 (0)