Commit 0555a87e by PLN (Algolia)

404: fixed 1280x720 letterbox stage, h/? code view, bottom-bar links (home left,…

404: fixed 1280x720 letterbox stage, h/? code view, bottom-bar links (home left, work right), StarryNights-only rotation, no stock-photo fallback
parent 4df36e72
import fs from 'fs'; import fs from 'fs';
import path from 'path'; import path from 'path';
import matter from 'gray-matter'; import matter from 'gray-matter';
import Link from 'next/link';
import NotFoundHydra from '@/components/not-found-hydra'; import NotFoundHydra from '@/components/not-found-hydra';
import { resolveHydraSketch } from '@/lib/hydra-sketch'; import { resolveHydraSketch } from '@/lib/hydra-sketch';
...@@ -12,7 +11,10 @@ export const metadata = { ...@@ -12,7 +11,10 @@ export const metadata = {
/** The void is a gallery: every StarryNights sketch in content/hydras is /** The void is a gallery: every StarryNights sketch in content/hydras is
* resolved at build (same pipeline as /hydra/[id]) and embedded, so each * resolved at build (same pipeline as /hydra/[id]) and embedded, so each
* visit boots one of the real pieces — never the same twice in a row. * visit boots one of the real pieces — and a sketch that won't boot yields
* to another, never to a stock photo. Non-StarryNights works (fantome,
* glitchpool…) stay in the /hydra gallery; the void only rotates the
* étoilées.
* Asset refs are rewritten to the static copies in /images/hydra (see * Asset refs are rewritten to the static copies in /images/hydra (see
* scripts/hydra-assets.mjs): the git-raw originals are cross-origin and * scripts/hydra-assets.mjs): the git-raw originals are cross-origin and
* case-fragile, and backgrounds vanished for some visitors. */ * case-fragile, and backgrounds vanished for some visitors. */
...@@ -29,6 +31,7 @@ async function loadSketches() { ...@@ -29,6 +31,7 @@ async function loadSketches() {
for (const f of fs.readdirSync(dir).filter((name) => name.endsWith('.md'))) { for (const f of fs.readdirSync(dir).filter((name) => name.endsWith('.md'))) {
const { data } = matter(fs.readFileSync(path.join(dir, f), 'utf8')); const { data } = matter(fs.readFileSync(path.join(dir, f), 'utf8'));
if (!data.source) continue; if (!data.source) continue;
if (!data.source.includes('/StarryNights/')) continue; // the void rotates the étoilées only
const sketch = await resolveHydraSketch(data.source); const sketch = await resolveHydraSketch(data.source);
if (sketch) { if (sketch) {
out.push({ out.push({
...@@ -44,11 +47,7 @@ async function loadSketches() { ...@@ -44,11 +47,7 @@ async function loadSketches() {
export default async function NotFound() { export default async function NotFound() {
const sketches = await loadSketches(); const sketches = await loadSketches();
return ( return (
<Link <div className="block relative min-h-[100dvh] cursor-pointer">
href="/"
aria-label="Retour à l’accueil"
className="block relative min-h-[100dvh] cursor-pointer"
>
<NotFoundHydra sketches={sketches} /> <NotFoundHydra sketches={sketches} />
<main <main
className="relative min-h-[100dvh] flex flex-col items-center justify-center px-6 text-center" className="relative min-h-[100dvh] flex flex-col items-center justify-center px-6 text-center"
...@@ -61,6 +60,6 @@ export default async function NotFound() { ...@@ -61,6 +60,6 @@ export default async function NotFound() {
Vous êtes dans l’Espace entre les Pages. Vous êtes dans l’Espace entre les Pages.
</p> </p>
</main> </main>
</Link> </div>
); );
} }
...@@ -4,10 +4,13 @@ import React, { useEffect, useRef, useState } from 'react'; ...@@ -4,10 +4,13 @@ import React, { useEffect, useRef, useState } from 'react';
/** The 404 canvas: boots one real StarryNights sketch per visit (embedded /** The 404 canvas: boots one real StarryNights sketch per visit (embedded
* at build by app/not-found.js). Cinema: the theme switcher sits out, and * at build by app/not-found.js). Cinema: the theme switcher sits out, and
* if hydra or WebGL can't run, a second sketch gets its chance before the * if a sketch can't boot, another gets its chance — the room never falls
* piece degrades to a random NASA star photo — the room is never black. * back to a stock photo. The stage stays 1280×720 (the format the sketches
* ctrl+h lifts the curtain on the running sketch's code; clicking the code * were composed for) and letterboxes, never stretches, on phone or ultrawide.
* opens the full work on /hydra/<id>. */ * `h` or `?` lifts the curtain on the running sketch's code; the bottom bar
* carries the links — Home left, the work's /hydra/<id> page right — and a
* click anywhere else goes home. On mobile, where no keyboard exists, the
* bottom bar IS the interface. */
function sanitize(source) { function sanitize(source) {
return source return source
...@@ -16,6 +19,9 @@ function sanitize(source) { ...@@ -16,6 +19,9 @@ function sanitize(source) {
.trim(); .trim();
} }
const STAGE_W = 1280;
const STAGE_H = 720;
export default function NotFoundHydra({ sketches }) { export default function NotFoundHydra({ sketches }) {
const canvasRef = useRef(null); const canvasRef = useRef(null);
const wrapRef = useRef(null); const wrapRef = useRef(null);
...@@ -29,7 +35,6 @@ export default function NotFoundHydra({ sketches }) { ...@@ -29,7 +35,6 @@ export default function NotFoundHydra({ sketches }) {
const pill = document.querySelector('[class*="ThemeSwitcher"], [class*="themeSwitcher"]'); const pill = document.querySelector('[class*="ThemeSwitcher"], [class*="themeSwitcher"]');
const prev = pill?.style.display; const prev = pill?.style.display;
if (pill) pill.style.display = 'none'; if (pill) pill.style.display = 'none';
const star = `/images/404/star-${String(1 + Math.floor(Math.random() * 31)).padStart(2, '0')}.jpg`;
let instance = null; let instance = null;
const boot = (piece) => { const boot = (piece) => {
...@@ -39,8 +44,8 @@ export default function NotFoundHydra({ sketches }) { ...@@ -39,8 +44,8 @@ export default function NotFoundHydra({ sketches }) {
instance = new HydraModule.default({ instance = new HydraModule.default({
canvas, canvas,
detectAudio: false, detectAudio: false,
width: canvas.width, width: STAGE_W,
height: canvas.height, height: STAGE_H,
}); });
instance.eval(sanitize(piece.source)); instance.eval(sanitize(piece.source));
bootedRef.current.push(piece); bootedRef.current.push(piece);
...@@ -58,41 +63,24 @@ export default function NotFoundHydra({ sketches }) { ...@@ -58,41 +63,24 @@ export default function NotFoundHydra({ sketches }) {
import('hydra-synth') import('hydra-synth')
.then((Hydra) => { .then((Hydra) => {
HydraModule = Hydra; HydraModule = Hydra;
const canvas = canvasRef.current; // a failing sketch yields to another one — no stock photo, ever
if (!canvas) return; for (let attempt = 0; attempt < 3 && !instance; attempt++) {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
// two sketches get their chance before the raw photo falls
for (let attempt = 0; attempt < 2; attempt++) {
const remaining = sketches.filter((s) => !bootedRef.current.includes(s)); const remaining = sketches.filter((s) => !bootedRef.current.includes(s));
const pool = remaining.length > 0 ? remaining : sketches; const pool = remaining.length > 0 ? remaining : sketches;
const piece = pool[Math.floor(Math.random() * pool.length)]; boot(pool[Math.floor(Math.random() * pool.length)]);
if (boot(piece)) {
const credit = document.createElement('div');
credit.textContent = `hydra · ${piece.title} · ctrl+h = code`;
credit.setAttribute('aria-hidden', 'true');
credit.style.cssText =
'position:fixed;right:1rem;bottom:0.9rem;z-index:1;font-size:0.75rem;opacity:0.55;color:var(--text-muted)';
wrapRef.current?.appendChild(credit);
break;
}
}
if (!instance && wrapRef.current) {
// no WebGL / no hydra at all? the raw photo still falls — cinema never black
wrapRef.current.style.background = `#0a0a0a url(${star}) center / cover no-repeat`;
} }
}) })
.catch((ex) => { .catch((ex) => {
console.error('hydra-synth import failed:', ex); console.error('hydra-synth import failed:', ex);
if (wrapRef.current) {
wrapRef.current.style.background = `#0a0a0a url(${star}) center / cover no-repeat`;
}
}); });
const onKey = (e) => { const onKey = (e) => {
if (e.ctrlKey && !e.metaKey && !e.altKey && e.key.toLowerCase() === 'h') { if (e.metaKey || e.ctrlKey || e.altKey) return;
if (e.key === 'h' || e.key === '?') {
e.preventDefault(); e.preventDefault();
setCodeOpen((open) => !open); setCodeOpen((open) => !open);
} else if (e.key === 'Escape') {
setCodeOpen(false);
} }
}; };
window.addEventListener('keydown', onKey); window.addEventListener('keydown', onKey);
...@@ -104,19 +92,62 @@ export default function NotFoundHydra({ sketches }) { ...@@ -104,19 +92,62 @@ export default function NotFoundHydra({ sketches }) {
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, [sketches]); }, [sketches]);
const goHome = () => window.location.assign('/');
const openWork = (e) => { const openWork = (e) => {
e.preventDefault(); e.preventDefault();
e.stopPropagation(); // the whole 404 is a link home; the code overlay is not e.stopPropagation(); // anywhere-else-click goes home; these links do not
if (current?.id) window.location.assign(`/hydra/${current.id}`); if (current?.id) window.location.assign(`/hydra/${current.id}`);
}; };
const barLink = {
color: 'var(--text-muted)',
textDecoration: 'none',
fontSize: '0.75rem',
opacity: 0.55,
};
return ( return (
<div ref={wrapRef} style={{ position: 'fixed', inset: 0, zIndex: 0 }}> <div
ref={wrapRef}
onClick={goHome}
style={{ position: 'fixed', inset: 0, zIndex: 0, display: 'flex', alignItems: 'center', justifyContent: 'center', background: '#0a0a0a' }}
>
<canvas <canvas
ref={canvasRef} ref={canvasRef}
width={STAGE_W}
height={STAGE_H}
aria-hidden="true" aria-hidden="true"
style={{ position: 'fixed', inset: 0, width: '100vw', height: '100vh', zIndex: 0 }} style={{
aspectRatio: '16 / 9',
width: '100vw',
height: 'auto',
maxHeight: '100vh',
maxWidth: 'calc(100vh * 16 / 9)',
}}
/> />
<div
style={{
position: 'fixed',
left: '1rem',
right: '1rem',
bottom: '0.9rem',
zIndex: 4,
display: 'flex',
justifyContent: 'space-between',
alignItems: 'baseline',
fontFamily: 'var(--font-mono, monospace)',
}}
>
<a href="/" onClick={(e) => e.stopPropagation()} style={barLink}>
← accueil
</a>
{current && (
<a href={`/hydra/${current.id}`} onClick={openWork} style={barLink}>
{current.title} · h = code
</a>
)}
</div>
{codeOpen && current && ( {codeOpen && current && (
<div <div
onClick={openWork} onClick={openWork}
...@@ -143,7 +174,7 @@ export default function NotFoundHydra({ sketches }) { ...@@ -143,7 +174,7 @@ export default function NotFoundHydra({ sketches }) {
fontFamily: 'var(--font-mono, monospace)', fontFamily: 'var(--font-mono, monospace)',
}} }}
> >
{current.title} — cliquer pour la pièce complète (/hydra/{current.id}) · ctrl+h pour {current.title} — cliquer pour la pièce complète (/hydra/{current.id}) · h ou ? pour
replier replier
</p> </p>
<pre <pre
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment