Skip to content

Commit

Permalink
deploy as static site
Browse files Browse the repository at this point in the history
- change to static adapter
- fix URL issues for hosting the static site in a subdirectory
- ensure everything server side is pre-rendered
- only show dev page on dev builds
  • Loading branch information
jakmeier committed Dec 22, 2023
1 parent 6075fb0 commit e9dcbf6
Show file tree
Hide file tree
Showing 15 changed files with 306 additions and 240 deletions.
299 changes: 162 additions & 137 deletions bouncy_frontend/package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions bouncy_frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"devDependencies": {
"@playwright/test": "^1.28.1",
"@sveltejs/adapter-auto": "^2.0.0",
"@sveltejs/adapter-static": "^2.0.3",
"@sveltejs/kit": "^1.27.4",
"date-fns": "^3.0.1",
"eslint": "^8.28.0",
Expand Down
52 changes: 0 additions & 52 deletions bouncy_frontend/src/app.css
Original file line number Diff line number Diff line change
@@ -1,55 +1,3 @@
@font-face {
font-family: 'Walkway';
src: url('fonts/WalkwaySemiBold.woff2') format('woff2'),
url('fonts/WalkwaySemiBold.woff') format('woff');
font-weight: 400;
font-style: normal;
font-display: swap;
}

@font-face {
font-family: 'Walkway';
src: url('fonts/WalkwayBold.woff2') format('woff2'), url('fonts/WalkwayBold.woff') format('woff');
font-weight: 700;
font-style: normal;
font-display: swap;
}

@font-face {
font-family: 'Walkway';
src: url('fonts/WalkwayBlack.woff2') format('woff2'),
url('fonts/WalkwayBlack.woff') format('woff');
font-weight: 900;
font-style: normal;
font-display: swap;
}

@font-face {
font-family: 'Walkway';
src: url('fonts/Walkway.woff2') format('woff2'), url('fonts/Walkway.woff') format('woff');
font-weight: 300;
font-style: normal;
font-display: swap;
}

@font-face {
font-family: 'Walkway Oblique';
src: url('fonts/WalkwayObliqueSemiBold.woff2') format('woff2'),
url('fonts/WalkwayObliqueSemiBold.woff') format('woff');
font-weight: 400;
font-style: normal;
font-display: swap;
}

@font-face {
font-family: 'Walkway Oblique';
src: url('fonts/WalkwayOblique.woff2') format('woff2'),
url('fonts/WalkwayOblique.woff') format('woff');
font-weight: 300;
font-style: normal;
font-display: swap;
}

/*
* Theme colors for re-use in all components.
* The theme is static for now.
Expand Down
62 changes: 62 additions & 0 deletions bouncy_frontend/src/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,66 @@
<div style="display: contents">%sveltekit.body%</div>
</body>

<style>
@font-face {
font-family: 'Walkway';
src:
url('%sveltekit.assets%/fonts/WalkwaySemiBold.woff2') format('woff2'),
url('%sveltekit.assets%/fonts/WalkwaySemiBold.woff') format('woff');
font-weight: 400;
font-style: normal;
font-display: swap;
}

@font-face {
font-family: 'Walkway';
src:
url('%sveltekit.assets%/fonts/WalkwayBold.woff2') format('woff2'),
url('%sveltekit.assets%/fonts/WalkwayBold.woff') format('woff');
font-weight: 700;
font-style: normal;
font-display: swap;
}

@font-face {
font-family: 'Walkway';
src:
url('%sveltekit.assets%/fonts/WalkwayBlack.woff2') format('woff2'),
url('%sveltekit.assets%/fonts/WalkwayBlack.woff') format('woff');
font-weight: 900;
font-style: normal;
font-display: swap;
}

@font-face {
font-family: 'Walkway';
src:
url('%sveltekit.assets%/fonts/Walkway.woff2') format('woff2'),
url('%sveltekit.assets%/fonts/Walkway.woff') format('woff');
font-weight: 300;
font-style: normal;
font-display: swap;
}

@font-face {
font-family: 'Walkway Oblique';
src:
url('%sveltekit.assets%/fonts/WalkwayObliqueSemiBold.woff2') format('woff2'),
url('%sveltekit.assets%/fonts/WalkwayObliqueSemiBold.woff') format('woff');
font-weight: 400;
font-style: normal;
font-display: swap;
}

@font-face {
font-family: 'Walkway Oblique';
src:
url('%sveltekit.assets%/fonts/WalkwayOblique.woff2') format('woff2'),
url('%sveltekit.assets%/fonts/WalkwayOblique.woff') format('woff');
font-weight: 300;
font-style: normal;
font-display: swap;
}
</style>

</html>
4 changes: 2 additions & 2 deletions bouncy_frontend/src/lib/pose.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import { PoseLandmarker, FilesetResolver } from '@mediapipe/tasks-vision';
import { Cartesian3d, Keypoints, KeypointsSide, loadPoseFile, loadStepFile } from './instructor/bouncy_instructor';

import { base } from '$app/paths';

export function landmarksToKeypoints(landmarks) {
const left = new KeypointsSide(
Expand Down Expand Up @@ -126,7 +126,7 @@ async function initMediaPipeBackend() {
{
baseOptions: {
// loading from a path (could also load from buffer)
modelAssetPath: 'models/pose_landmarker_full.task',
modelAssetPath: `${base}/models/pose_landmarker_full.task`,
},
runningMode: "VIDEO",
numPoses: 1,
Expand Down
3 changes: 3 additions & 0 deletions bouncy_frontend/src/routes/+layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import {
steps,
} from '$lib/instructor/bouncy_instructor';

export const prerender = true;
export const trailingSlash = 'always';

let loadedOnce = false;

/** @type {import('@sveltejs/kit').Load} */
Expand Down
7 changes: 6 additions & 1 deletion bouncy_frontend/src/routes/+layout.server.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { locales, loadTranslations, defaultLocale, translations } from '$lib/i18n.js';

export const prerender = true;

/** @type {import('@sveltejs/kit').ServerLoad} */
export const load = async ({ fetch, url, cookies, request }) => {
const { pathname } = url;
Expand All @@ -10,7 +12,10 @@ export const load = async ({ fetch, url, cookies, request }) => {
// Get user preferred locale
if (!locale) {
// TODO: better locale detection: find closest match instead of exact match only
locale = request.headers.get('accept-language').split(/,/)[0];
const header = request.headers.get('accept-language');
if (header) {
locale = header.split(/,/)[0];
}
}

// Get defined locales
Expand Down
31 changes: 0 additions & 31 deletions bouncy_frontend/src/routes/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,37 +1,6 @@
<script>
import { t } from '$lib/i18n.js';
import { onMount } from 'svelte';
import Step from './Step.svelte';
import { readable } from 'svelte/store';
/** @type {import('./$types').PageData} */
export let data;
const i = readable(0, (set) => {
const handle = setInterval(() => {
set($i + 1);
}, 300);
return () => clearInterval(handle);
});
</script>

<h1>{$t('home.title')}</h1>
<p>[intro video]</p>
<p>[recommendations]</p>

<h2>{$t('home.steps')}</h2>
<div class="step-table">
{#each data.allSteps as step}
<Step {step} poseIndex={$i} />
{/each}
</div>

<style>
.step-table {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
text-align: center;
gap: 20px 0px;
}
</style>
27 changes: 20 additions & 7 deletions bouncy_frontend/src/routes/TabNavigation.svelte
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
<script>
import { page } from '$app/stores';
import { t } from '$lib/i18n.js';
import { base } from '$app/paths';
import { dev } from '$app/environment';
export let height = 100;
const tabs = [
{ label: $t('home.nav'), icon: 'home', route: '/' },
// { label: $t('learn.nav'), icon: 'book_5', route: '/learn' },
{ label: $t('record.nav'), icon: 'directions_walk', route: '/record' },
{ label: $t('profile.nav'), icon: 'account_circle', route: '/profile' },
{ label: 'Dev', icon: 'code', route: '/dev' },
{ label: $t('home.nav'), icon: 'home', route: `${base}/` },
{ label: $t('learn.nav'), icon: 'book_5', route: `${base}/learn` },
{
label: $t('record.nav'),
icon: 'directions_walk',
route: `${base}/record`,
},
{
label: $t('profile.nav'),
icon: 'account_circle',
route: `${base}/profile`,
},
];
if (dev) {
tabs.push({ label: 'Dev', icon: 'code', route: `${base}/dev` });
}
</script>

<nav class="navbar" style="height:{height}px">
Expand All @@ -28,8 +40,9 @@

<style>
.navbar {
display: grid;
grid-template-columns: auto auto auto auto;
display: flex;
flex-flow: row;
justify-content: space-around;
overflow: hidden;
background-color: var(--theme-neutral-dark);
position: fixed;
Expand Down
1 change: 1 addition & 0 deletions bouncy_frontend/src/routes/dev/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@

<h1>Dev</h1>

<!-- svelte-ignore a11y-media-has-caption -->
<video bind:this={video} playsinline controls></video>
<p>
<input
Expand Down
30 changes: 29 additions & 1 deletion bouncy_frontend/src/routes/learn/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,34 @@
<script>
import { t } from '$lib/i18n.js';
import Step from './Step.svelte';
import { readable } from 'svelte/store';
/** @type {import('./$types').PageData} */
export let data;
const i = readable(0, (set) => {
const handle = setInterval(() => {
set($i + 1);
}, 300);
return () => clearInterval(handle);
});
</script>

<h1>{$t('learn.title')}</h1>
<p>[skill tree selection]</p>

<h2>{$t('home.steps')}</h2>
<div class="step-table">
{#each data.allSteps as step}
<Step {step} poseIndex={$i} />
{/each}
</div>

<style>
.step-table {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
text-align: center;
gap: 20px 0px;
}
</style>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script>
import Canvas from '$lib/Canvas.svelte';
import Area from './record/Area.svelte';
import Avatar from './record/Avatar.svelte';
import Area from '../record/Area.svelte';
import Avatar from '../record/Avatar.svelte';
import SvgAvatar from '$lib/avatar/SvgAvatar.svelte';
/** @type {import('$lib/instructor/bouncy_instructor').StepInfo} */
Expand Down
1 change: 1 addition & 0 deletions bouncy_frontend/src/routes/record/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@
</button>
{/if}
</div>
<p style="width: 100px; height: 50px;"></p>
</div>

<style>
Expand Down
5 changes: 3 additions & 2 deletions bouncy_frontend/src/routes/record/Banner.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { onMount } from 'svelte';
import BannerStep from './BannerStep.svelte';
import { base } from '$app/paths';
const avatarSize = 60;
Expand Down Expand Up @@ -73,7 +74,7 @@
</script>

<div id="container" bind:clientWidth={visibleBannerWidth}>
<img class="arrow" src="img/left_arrow.svg" alt="left arrow" />
<img class="arrow" src="{base}/img/left_arrow.svg" alt="left arrow" />
<div id="steps" bind:this={stepsDiv} on:scroll={scrolled}>
{#each steps as step}
<BannerStep
Expand All @@ -90,7 +91,7 @@
></div>
</div>
<div id="marker"></div>
<img class="invert arrow" src="img/left_arrow.svg" alt="left arrow" />
<img class="invert arrow" src="{base}/img/left_arrow.svg" alt="left arrow" />
</div>

<style>
Expand Down
19 changes: 14 additions & 5 deletions bouncy_frontend/svelte.config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
import { vitePreprocess } from '@sveltejs/kit/vite';
import adapter from '@sveltejs/adapter-auto';
import adapter from '@sveltejs/adapter-static';

/** @type {import('@sveltejs/kit').Config} */
const config = {
kit: {
// adapter-auto only supports some environments, see https://kit.svelte.dev/docs/adapter-auto for a list.
// If your environment is not supported or you settled on a specific environment, switch out the adapter.
// See https://kit.svelte.dev/docs/adapters for more information about adapters.
adapter: adapter()
adapter: adapter({
pages: 'build',
assets: 'build',
fallback: 'index.html',
precompress: false,
strict: true,
prerender: {
default: true,
}
}),
paths: {
base: process.env.NODE_ENV === 'development' ? '' : '/bouncy-feet',
}
},

preprocess: [vitePreprocess({})]
Expand Down

0 comments on commit e9dcbf6

Please sign in to comment.