Publish a browser-only demo to GitHub Pages

Self-hosting is a fair ask once someone knows they want the app, but it's a lot
to ask of someone deciding whether to look at it at all. A demo build (VITE_DEMO=1)
drops the parts that need the backend — passkeys, sync, admin — and boots straight
into guest mode with a seeded example profile, so every screen has real data behind
it: twelve weeks of Push/Pull/Legs with progression and the odd missed session,
twice-weekly weigh-ins trending toward a goal, PRs, and today's session moved onto
the current day so there's always something to press Start on.

The seed generator is imported dynamically and the demo-only UI folds away at build
time, so none of it lands in the bundle self-hosters ship. Exercise media (~140 MB)
isn't committed anywhere, so the demo build points VITE_IMG_BASE / VITE_GIF_BASE at
the upstream dataset on jsDelivr, pinned to a commit; unset, both still resolve to
img/ and gif/ next to the app exactly as before.

Deployed by a Pages workflow on every push to main.
This commit is contained in:
Duarte Santos committed 2026-07-23 12:42:40 +02:00
1 parent 3c5bcd5957
commit e9bf38f39b
11 files changed
+281 -15

No files matched your search

+60
View File
@@ -0,0 +1,60 @@
# Publishes the browser-only demo to GitHub Pages: https://duartesantos8.github.io/openGym/
#
# Pages serves static files only, so this build has no backend — VITE_DEMO=1 makes the app
# boot straight into guest mode with a seeded example history (see frontend/src/lib/demo.js).
# The exercise images/GIFs (~140 MB) are never committed here; the demo build points at the
# upstream dataset on jsDelivr instead, pinned to a commit so the CDN can cache it forever.
name: Deploy demo to GitHub Pages
on:
push:
branches: [main]
paths:
- 'frontend/**'
- '.github/workflows/pages.yml'
workflow_dispatch:
permissions:
contents: read
pages: write
id-token: write
concurrency:
group: pages
cancel-in-progress: true
env:
DATASET: https://cdn.jsdelivr.net/gh/hasaneyldrm/exercises-dataset@7455efae41b330c265e7cd4b78dfa848e7ce5ebd
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
cache-dependency-path: frontend/package-lock.json
- run: npm ci
working-directory: frontend
- run: npm run build
working-directory: frontend
env:
VITE_DEMO: '1'
VITE_IMG_BASE: ${{ env.DATASET }}/images/
VITE_GIF_BASE: ${{ env.DATASET }}/videos/
- uses: actions/configure-pages@v5
- uses: actions/upload-pages-artifact@v3
with:
path: frontend/dist
deploy:
needs: build
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deploy.outputs.page_url }}
steps:
- id: deploy
uses: actions/deploy-pages@v4
+11
View File
@@ -1,5 +1,16 @@
# Changelog
## Unreleased
- ▶️ **Live demo** at [duartesantos8.github.io/openGym](https://duartesantos8.github.io/openGym/) —
a browser-only build (`VITE_DEMO=1`) published to GitHub Pages on every push to `main`. It boots
into guest mode with a seeded example profile (12 weeks of Push/Pull/Legs, weigh-ins, PRs) so
every screen has something to show, and it never talks to a server. Passkeys, sync and the admin
dashboard stay exclusive to self-hosted instances, which is where the backend lives.
- 🖼️ Builds can point the exercise media elsewhere via `VITE_IMG_BASE` / `VITE_GIF_BASE` — the demo
serves the ~140 MB dataset from a CDN instead of shipping it. The default (`img/` and `gif/` next
to the app) is unchanged.
## v1.2.0 — 2026-07-23
A complete visual redesign. Same app, same data — every screen redrawn.
+10
View File
@@ -37,6 +37,16 @@ No account on someone else's server, no subscription, no ads. Just `docker compo
</table>
</div>
<div align="center">
### [▶ Try the live demo](https://duartesantos8.github.io/openGym/)
No signup, nothing to install — it runs entirely in your browser on example data.<br>
<sub>There's no server behind the demo, so passkey sign-in, sync across devices and the
admin dashboard only exist in a self-hosted instance.</sub>
</div>
## Why
Most workout apps lock your data behind a login on their servers, nag you to upgrade, or
+14
View File
@@ -0,0 +1,14 @@
// Demo build (VITE_DEMO=1) — what runs on the GitHub Pages deployment.
//
// Pages can only serve static files, so there is no API: passkey sign-in, per-profile sync
// and the admin dashboard all need the Node backend and are simply not part of a demo build.
// The app therefore stays in guest mode (everything in localStorage) and boots with a seeded
// example history (demoSeed.js), so the charts, heatmap, streaks and "last time you lifted…"
// pre-fills have something to show instead of an empty shell.
//
// Only these three constants are shared with normal builds: Vite replaces VITE_DEMO at build
// time, so the demo-only UI folds away and the seed generator — imported dynamically — never
// lands in a self-hosted bundle.
export const DEMO = import.meta.env.VITE_DEMO === '1'
export const DEMO_SEEDED = 'gym_demo_seeded_v1'
export const REPO = 'https://github.com/DuarteSantos8/openGym'
+108
View File
@@ -0,0 +1,108 @@
// The example profile behind the demo build (see demo.js). Imported dynamically, so it stays
// out of the bundle self-hosters ship.
import { isoOf, uid } from './format.js'
import { starterRoutines } from './starter.js'
// Starting weight and weekly increment per exercise of the starter plan (kg).
// Chest dips are body-weight only here, so they log reps at 0 added weight.
const PROG = {
'0025': [60, 1.25], '0047': [45, 1], '0426': [20, 0.5], '0334': [10, 0.25], '0241': [25, 0.75], '0251': [0, 0],
'2330': [50, 1.25], '0027': [50, 1], '1323': [45, 1], '0031': [30, 0.5], '0313': [12, 0.3],
'0043': [70, 1.5], '0085': [60, 1.25], '0739': [120, 3], '0585': [45, 1], '0586': [40, 1], '0605': [60, 1.5]
}
const WEEKS = 12 // how much history to fabricate
const BW_FROM = 82.4, BW_TO = 78.3 // body-weight trend across those weeks
const TARGET_W = 77
// Deterministic PRNG — the demo should look the same on every visit and in screenshots.
function rng(seed) {
let a = seed >>> 0
return () => {
a = (a + 0x6d2b79f5) >>> 0
let t = Math.imul(a ^ (a >>> 15), 1 | a)
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t
return ((t ^ (t >>> 14)) >>> 0) / 4294967296
}
}
const round = (w, step) => Math.round(w / step) * step
const at = (date, h, m) => { const d = new Date(date); d.setHours(h, m, 0, 0); return d.getTime() }
// A full example profile: 12 weeks of Mon/Wed/Fri sessions on the starter plan, with linear
// progression, the odd missed session, and twice-weekly weigh-ins trending toward the goal.
export function buildDemoState() {
const rnd = rng(20260723)
const [push, pull, legs] = starterRoutines()
const byWeekday = { 1: push, 3: pull, 5: legs }
const nowH = new Date().getHours()
const today = new Date(); today.setHours(12, 0, 0, 0)
const start = new Date(today); start.setDate(start.getDate() - WEEKS * 7)
const workouts = []
const bodyweight = []
const exWeights = {}
const best = {}
for (let d = new Date(start); d <= today; d.setDate(d.getDate() + 1)) {
const day = new Date(d)
const iso = isoOf(day)
const weekIdx = Math.floor((day - start) / (7 * 86400000))
const p = Math.min(1, weekIdx / WEEKS)
// weigh-ins: Monday and Thursday mornings
if (day.getDay() === 1 || day.getDay() === 4) {
const w = BW_FROM + (BW_TO - BW_FROM) * p + (rnd() - 0.5) * 0.7
bodyweight.push({ d: iso, w: Math.round(w * 10) / 10, t: at(day, 7, 30) })
}
const routine = byWeekday[day.getDay()]
if (!routine) continue
if (rnd() < 0.09) continue // life happens — a few missed sessions
if (iso === isoOf(today) && nowH < 18) continue // leave today's session to try out, unless it's already evening
const prs = []
const entries = routine.ex.map(cfg => {
const [base, inc] = PROG[cfg.id] || [20, 0.5]
const step = base >= 40 ? 2.5 : 1.25
const w = base ? Math.max(step, round(base + inc * weekIdx, step)) : 0
const sets = []
for (let i = 0; i < cfg.sets; i++) {
// last set is where reps usually start slipping
const drop = i === cfg.sets - 1 && rnd() < 0.55 ? (rnd() < 0.4 ? 2 : 1) : 0
sets.push({ w, r: Math.max(4, cfg.reps - drop), done: true })
}
if (w > (best[cfg.id] || 0)) { best[cfg.id] = w; prs.push(cfg.id) }
exWeights[cfg.id] = { w: Math.max(w, exWeights[cfg.id]?.w || 0), d: iso }
return { id: cfg.id, sets, topW: w || null }
})
const bw = bodyweight.length ? bodyweight[bodyweight.length - 1].w : BW_FROM
const startMs = at(day, 18, 5 + Math.floor(rnd() * 25))
const w = {
id: uid(), d: iso, start: startMs, end: startMs + (46 + Math.floor(rnd() * 26)) * 60000,
routineId: routine.id, name: routine.name, bw,
entries,
prs: weekIdx === 0 ? [] : prs // the very first session isn't a PR party
}
w.vol = entries.reduce((v, e) => v + e.sets.reduce((n, s) => n + s.w * s.r, 0), 0)
workouts.push(w)
}
// A visitor should always have something to press "Start" on, so if they land on a rest day
// the next routine in the rotation is moved onto today — which also shows off rescheduling.
const dayPlan = {}
const tIso = isoOf(today)
if (!byWeekday[today.getDay()] && !workouts.some(w => w.d === tIso)) {
const order = [push, pull, legs]
const lastName = workouts.length ? workouts[workouts.length - 1].name : legs.name
dayPlan[tIso] = order[(order.findIndex(r => r.name === lastName) + 1) % order.length].id
}
return {
routines: [push, pull, legs],
week: { 1: push.id, 3: pull.id, 5: legs.id },
dayPlan,
workouts, bodyweight, exWeights,
targetW: TARGET_W
}
}
+7 -2
View File
@@ -25,8 +25,13 @@ export function registerCustom(list) {
// Full searchable catalogue — customs first so your own exercises are easy to find.
export const allExercises = st => [...(st.customEx || []), ...EXDB]
export const imgSrc = ex => 'img/' + ex.img
export const gifSrc = ex => 'gif/' + ex.gif
// Media normally sits next to the app (img/ and gif/, mounted into the web container).
// A build can point them somewhere else — the demo build pulls them off a CDN instead of
// shipping ~140 MB of images into the deployment.
const IMG_BASE = import.meta.env.VITE_IMG_BASE || 'img/'
const GIF_BASE = import.meta.env.VITE_GIF_BASE || 'gif/'
export const imgSrc = ex => IMG_BASE + ex.img
export const gifSrc = ex => GIF_BASE + ex.gif
// Cardio exercises log time + speed instead of weight × reps.
export const isCardio = idOrEx => (typeof idOrEx === 'string' ? EXIDX[idOrEx] : idOrEx)?.bp === 'cardio'
+13
View File
@@ -0,0 +1,13 @@
// The Push/Pull/Legs starter plan. Shared by the "Load starter plan" action in Settings
// and by the demo build, which seeds a history on top of exactly these routines.
import { uid } from './format.js'
const SPEC = [
['Push Day', 'barbell', [['0025', 4, 8], ['0047', 3, 10], ['0426', 3, 10], ['0334', 3, 12], ['0241', 3, 12], ['0251', 3, 10]]],
['Pull Day', 'pullup', [['2330', 4, 10], ['0027', 4, 8], ['1323', 3, 10], ['0031', 3, 10], ['0313', 3, 12]]],
['Leg Day', 'legs', [['0043', 4, 8], ['0085', 3, 10], ['0739', 3, 12], ['0585', 3, 12], ['0586', 3, 12], ['0605', 4, 15]]]
]
// Fresh routine objects (new ids) — [push, pull, legs].
export const starterRoutines = () =>
SPEC.map(([name, emoji, list]) => ({ id: uid(), name, emoji, ex: list.map(([id, sets, reps]) => ({ id, sets, reps, weight: 0 })) }))
+2 -4
View File
@@ -7,6 +7,7 @@ import { lastEntryFor, bestWeightFor, buildSets, effectiveRoutineId, workoutVolu
import { beep, vibrate } from './lib/sound.js'
import { t, instrFor, getLang, INSTR_LANGS } from './lib/i18n.js'
import { nav } from './lib/nav.js'
import { starterRoutines } from './lib/starter.js'
import Media, { Thumb } from './components/Media.jsx'
import Stepper from './components/Stepper.jsx'
import Icon from './components/Icon.jsx'
@@ -36,11 +37,8 @@ export function confirmSheet(opts) {
/* ============================ starter plan ============================ */
export function loadStarterPlan() {
const mk = (name, emoji, list) => ({ id: uid(), name, emoji, ex: list.map(([id, sets, reps]) => ({ id, sets, reps, weight: 0 })) })
const [push, pull, legs] = starterRoutines()
update(st => {
const push = mk('Push Day', 'barbell', [['0025', 4, 8], ['0047', 3, 10], ['0426', 3, 10], ['0334', 3, 12], ['0241', 3, 12], ['0251', 3, 10]])
const pull = mk('Pull Day', 'pullup', [['2330', 4, 10], ['0027', 4, 8], ['1323', 3, 10], ['0031', 3, 10], ['0313', 3, 12]])
const legs = mk('Leg Day', 'legs', [['0043', 4, 8], ['0085', 3, 10], ['0739', 3, 12], ['0585', 3, 12], ['0586', 3, 12], ['0605', 4, 15]])
st.routines.push(push, pull, legs)
st.week[1] = push.id; st.week[3] = pull.id; st.week[5] = legs.id
})
+19
View File
@@ -2,6 +2,7 @@ import { create } from 'zustand'
import { api } from '../lib/api.js'
import { localTZ } from '../lib/format.js'
import { registerCustom } from '../lib/exercises.js'
import { DEMO, DEMO_SEEDED } from '../lib/demo.js'
const KEY = 'gym_state_v1'
export const DEF = {
@@ -98,8 +99,26 @@ export const useStore = create((set, get) => {
persist(clone(DEF), false)
},
// Demo build only: drop the seeded example profile back in (Settings → "Reset demo data").
// Dynamic import so the generator never ships in a self-hosted bundle.
async resetDemo() {
const { buildDemoState } = await import('../lib/demoSeed.js')
localStorage.removeItem('gym_dirty')
persist(Object.assign(clone(DEF), buildDemoState()), false)
},
// Boot: ask the server who we are, then pull.
async boot() {
// Demo build (GitHub Pages): no backend at all — seed once, stay in guest mode.
if (DEMO) {
if (!localStorage.getItem(DEMO_SEEDED)) {
localStorage.setItem(DEMO_SEEDED, '1')
await get().resetDemo()
}
get().setGuest(true)
set({ ready: true })
return
}
try {
const me = await api('/api/me')
get().setUser(me.user)
+24 -3
View File
@@ -3,6 +3,7 @@ import { useUI } from '../store/useUI.js'
import { webauthnOK, passkeyLogin, passkeyRegister, api, BIO } from '../lib/api.js'
import { hasData } from '../store/useStore.js'
import { t } from '../lib/i18n.js'
import { DEMO, REPO } from '../lib/demo.js'
import { useState, useRef, useEffect } from 'react'
import Icon from '../components/Icon.jsx'
import { Button } from '../components/ui.jsx'
@@ -47,10 +48,30 @@ export default function Login() {
try { const u = await passkeyLogin(); setUser(u); await pullState(); useUI.getState().toast(t('Welcome back, {0}', u.name)) }
catch (e) { if (e.name !== 'NotAllowedError' && e.name !== 'AbortError') useUI.getState().toast(e.message || t('Sign-in failed')) }
}
const head = <>
<div style={{ fontSize: 54, display: 'flex', justifyContent: 'center', color: 'var(--acc)' }}><Icon name="dumbbell" /></div>
<h1 style={{ fontSize: 34, fontWeight: 700, letterSpacing: '-.028em', margin: '10px 0 4px' }}>openGym</h1>
</>
const wrap = { display: 'flex', flexDirection: 'column', justifyContent: 'center', minHeight: '78vh', textAlign: 'center' }
// Demo build: no backend to sign in against — the only way in is the local guest profile.
if (DEMO) return (
<div className="narrow" style={wrap}>
{head}
<div className="muted" style={{ marginBottom: 30 }}>{t('Live demo — everything stays in this browser.')}</div>
<Button variant="primary" icon="sparkles" onClick={() => setGuest(true)}>{t('Start the demo')}</Button>
<div className="card small muted" style={{ textAlign: 'left', marginTop: 16 }}>
{t('This demo runs entirely in your browser on example data — nothing is sent anywhere. Passkey sign-in and sync across your devices come with the openGym server, which you get by self-hosting it.')}
</div>
<div className="dim small" style={{ marginTop: 22, lineHeight: 1.6 }}>
<a href={REPO} target="_blank" rel="noopener">{t('Self-host it in a minute →')}</a>
</div>
</div>
)
return (
<div className="narrow" style={{ display: 'flex', flexDirection: 'column', justifyContent: 'center', minHeight: '78vh', textAlign: 'center' }}>
<div style={{ fontSize: 54, display: 'flex', justifyContent: 'center', color: 'var(--acc)' }}><Icon name="dumbbell" /></div>
<h1 style={{ fontSize: 34, fontWeight: 700, letterSpacing: '-.028em', margin: '10px 0 4px' }}>openGym</h1>
<div className="narrow" style={wrap}>
{head}
<div className="muted" style={{ marginBottom: 34 }}>{t('Your workouts. Your weights. Your profile.')}</div>
{webauthnOK() ? <>
<Button variant="primary" icon="person" onClick={signIn}>{t('Sign in with passkey')}</Button>
+13 -6
View File
@@ -6,6 +6,7 @@ import { ACCENTS, todayISO, localTZ } from '../lib/format.js'
import { webauthnOK, passkeyLogin, passkeyRegister, IS_ANDROID } from '../lib/api.js'
import { pushSupported, enablePush, disablePush, sendTestPush } from '../lib/push.js'
import { t, LANGS, INSTR_LANGS } from '../lib/i18n.js'
import { DEMO, REPO } from '../lib/demo.js'
import { loadStarterPlan, confirmSheet } from '../sheets.jsx'
import Icon from '../components/Icon.jsx'
import { Section, Row, SelectRow, Switch, Segmented, Button, TextField } from '../components/ui.jsx'
@@ -14,7 +15,7 @@ export default function Settings() {
const nav = useNavigate()
const S = useStore(s => s.S)
const user = useStore(s => s.user)
const { update, replaceState, setUser, pullState, pushState, signOut } = useStore()
const { update, replaceState, setUser, pullState, pushState, signOut, resetDemo } = useStore()
const toast = useUI(s => s.toast)
const fileRef = useRef(null)
@@ -47,9 +48,15 @@ export default function Settings() {
<div style={{ flex: 1, marginLeft: 10 }}><h1>{t('Settings')}</h1></div>
</div>
{/* ---------- account ---------- */}
<Section title={t('Account')}>
{user ? <>
{/* ---------- account (demo builds have nothing to sign in to) ---------- */}
<Section title={DEMO ? t('Demo') : t('Account')}>
{DEMO ? <>
<Row icon="sparkles" iconTint="var(--acc)" title={t('You’re in the demo')} subtitle={t('Example data, stored only in this browser — change anything you like.')} />
<Row icon="reset" iconTint="var(--blue)" title={t('Reset demo data')} accessory="chevron"
onClick={() => confirmSheet({ title: t('Reset demo data?'), message: t('Puts the example plan, workouts and weigh-ins back the way they started.'), confirmText: t('Reset'), onConfirm: () => { resetDemo(); nav('/home'); toast(t('Demo data reset')) } })} />
<Row icon="rocket" iconTint="var(--indigo)" title={t('Self-host openGym')} subtitle={t('Passkey sign-in, sync across your devices, your own data.')} accessory="chevron"
onClick={() => window.open(REPO, '_blank', 'noopener')} />
</> : user ? <>
<Row icon="personCircle" iconTint="var(--grey)" title={user.name} subtitle={t('Signed in with passkey — data syncs to this profile.')} />
{user.admin && <Row icon="wrench" iconTint="var(--indigo)" title={t('Admin dashboard')} accessory="chevron" onClick={() => nav('/admin')} />}
<Row icon="signOut" iconTint="var(--red)" title={t('Sign out')} danger onClick={() => confirmSheet({ title: t('Sign out?'), message: t('Your data is synced to your profile first, then cleared from this device.'), confirmText: t('Sign out'), danger: true, onConfirm: () => { signOut(); nav('/home') } })} />
@@ -60,10 +67,10 @@ export default function Settings() {
<Row icon="lock" iconTint="var(--grey)" title={t('Passkeys not supported in this browser.')} />
)}
</Section>
{!user && <p className="sect-f" style={{ marginTop: -18, marginBottom: 22 }}>{t('Guest mode — data lives only in this browser.')}</p>}
{!user && !DEMO && <p className="sect-f" style={{ marginTop: -18, marginBottom: 22 }}>{t('Guest mode — data lives only in this browser.')}</p>}
{/* ---------- appearance ---------- */}
<Section title={t('Appearance')} footer={t('synced with your profile')}>
<Section title={t('Appearance')} footer={DEMO ? undefined : t('synced with your profile')}>
<SelectRow
icon="globe" iconTint="var(--blue)" title={t('Language')}
value={S.lang || 'en'} onChange={v => update(s => { s.lang = v })}