Skip to content

Commit b1174dc

Browse files
committed
Build Github Pages
1 parent 84f2b27 commit b1174dc

File tree

4 files changed

+86
-16
lines changed

4 files changed

+86
-16
lines changed

.github/workflows/github-pages.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# From https://book.leptos.dev/deployment/csr.html#github-pages
2+
name: Release to Github Pages
3+
4+
on:
5+
push:
6+
branches: [main, add-wasm-backend]
7+
workflow_dispatch:
8+
9+
permissions:
10+
contents: write # for committing to gh-pages branch.
11+
pages: write
12+
id-token: write
13+
14+
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
15+
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
16+
concurrency:
17+
group: "pages"
18+
cancel-in-progress: false
19+
20+
env:
21+
WASM_PATH: ./examples/wasm
22+
23+
jobs:
24+
Github-Pages-Release:
25+
defaults:
26+
run:
27+
working-directory: ${{ env.WASM_PATH }}
28+
29+
timeout-minutes: 10
30+
31+
environment:
32+
name: github-pages
33+
url: ${{ steps.deployment.outputs.page_url }}
34+
35+
runs-on: ubuntu-latest
36+
37+
steps:
38+
- uses: actions/checkout@v4 # repo checkout
39+
40+
# Install Rust Nightly Toolchain, with Clippy & Rustfmt
41+
- name: Install nightly Rust
42+
uses: dtolnay/rust-toolchain@nightly
43+
44+
- name: Add WASM target
45+
run: rustup target add wasm32-unknown-unknown
46+
47+
- name: Download and install Trunk binary
48+
run: wget -qO- https://github.com/trunk-rs/trunk/releases/download/v0.21.14/trunk-x86_64-unknown-linux-gnu.tar.gz | tar -xzf-
49+
50+
- name: Build with Trunk
51+
# The behavior of the --public-url argument has changed: it no longer includes a leading '/'.
52+
# We now need to specify it explicitly. See https://github.com/trunk-rs/trunk/issues/668
53+
run: ./trunk build --release --public-url "/${GITHUB_REPOSITORY#*/}"
54+
55+
# Deploy with Github Static Pages
56+
- name: Setup Pages
57+
uses: actions/configure-pages@v5
58+
with:
59+
enablement: true
60+
# token:
61+
62+
- name: Upload artifact
63+
uses: actions/upload-pages-artifact@v3
64+
with:
65+
# Upload dist dir
66+
path: "${{ env.WASM_PATH }}/dist"
67+
68+
- name: Deploy to GitHub Pages 🚀
69+
id: deployment
70+
uses: actions/deploy-pages@v4

examples/wasm/game.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ const Utils = {
6969
};
7070

7171
// Game elements
72-
const canvas = document.getElementById("gameCanvas");
72+
const canvas = document.getElementById("game-canvas");
7373
const ctx = canvas.getContext("2d");
7474
const UI = {
75-
gameOverMessage: document.getElementById("gameOverMessage"),
76-
restartButton: document.getElementById("restartButton"),
77-
shareButton: document.getElementById("shareButton"),
75+
gameOverMessage: document.getElementById("game-over"),
76+
restartButton: document.getElementById("restart-button"),
77+
shareButton: document.getElementById("share-button"),
7878
floatingText: "keymap-rs",
7979
};
8080

examples/wasm/index.css

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ canvas {
8080
font-size: 1.6em;
8181
text-align: right;
8282
}
83-
#gameOverMessage {
83+
#game-over {
8484
position: absolute;
8585
top: 33%;
8686
left: 50%;
@@ -108,23 +108,23 @@ canvas {
108108
z-index: 10;
109109
display: none;
110110
}
111-
#restartButton {
111+
#restart-button {
112112
top: calc(50% + 20px); /* Position below game over message */
113113
border: 2px solid #059669; /* Darker green border */
114114
background-color: #10b981; /* Modern green */
115115
box-shadow: 2px 2px 0px #059669;
116116
}
117-
#restartButton:hover {
117+
#restart-button:hover {
118118
background-color: #059669;
119119
}
120-
#shareButton {
120+
#share-button {
121121
font-size: 0.7em;
122122
top: calc(50% + 80px);
123123
border: 2px solid #ddd;
124124
background-color: #0E0E0E;
125125
box-shadow: 2px 2px 0px #9b9b9b;
126126
}
127-
#shareButton:hover {
127+
#share-button:hover {
128128
background-color: #282828;
129129
}
130130
.rainbow {

examples/wasm/index.html

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ <h1>
2929
</p>
3030
<h3>DEMO: Nyan Jump! (WASM Edition)</h3>
3131
<div class="game-container">
32-
<canvas id="gameCanvas" width="600" height="300"></canvas>
33-
<div id="gameOverMessage">GAME OVER!</div>
34-
<button id="restartButton">Restart</button>
35-
<button id="shareButton">Share on X</button>
32+
<canvas id="game-canvas" width="600" height="300"></canvas>
33+
<div id="game-over">GAME OVER!</div>
34+
<button id="restart-button">Restart</button>
35+
<button id="share-button">Share on X</button>
3636
</div>
3737
<h4>EXAMPLE: Derive Macro</h4>
3838
<p>
@@ -67,9 +67,9 @@ <h4>EXAMPLE: Key Override</h4>
6767
<pre><code class="language-yaml"># Now both 'space' and the 'up' arrow can be used to jump
6868
Jump = { keys = ["space", "up"], description = "Jump Jump!" }
6969
</code></pre>
70-
<script src="https://unpkg.com/@highlightjs/[email protected]/highlight.min.js"></script>
71-
<script src="https://unpkg.com/@highlightjs/[email protected]/languages/rust.min.js"></script>
72-
<script type="module">
70+
<script src="https://unpkg.com/@highlightjs/[email protected]/highlight.min.js" defer></script>
71+
<script src="https://unpkg.com/@highlightjs/[email protected]/languages/rust.min.js" defer></script>
72+
<script type="module" defer>
7373
// Initialize syntax highlighting
7474
hljs.highlightAll();
7575
</script>

0 commit comments

Comments
 (0)