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

+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 })) }))