The operator wants to browse the posters the way a Plex or Emby Formula 1 library shows them. The page reads the whole library from the one Kometa file (rounds, race names in the race posters' addresses, sessions in the episodes'), waits through a fresh server's minutes-long first answer instead of failing, and loads each picture only when it is on screen, two at a time, dropping the queue when the reader leaves a level: every poster is a render of about 10 s that pulls map tiles. Each level has its own address and back/forward work; a picture the server has none for is a plain card with its name. The session order per weekend format moves into site.js, so the posters page and the library read the same list. Claude-Session: https://claude.ai/code/session_01NcbgfJAa38xFpzy69BWrqh
211 lines
8.9 KiB
HTML
211 lines
8.9 KiB
HTML
<!doctype html>
|
||
<html lang="en">
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||
<title>Posters · F1 Circuits API examples</title>
|
||
<meta name="description" content="Render F1 race posters, season posters and session thumbnails for Plex from the F1 Circuits API.">
|
||
<link rel="icon" href="data:,">
|
||
<link rel="stylesheet" href="site.css">
|
||
</head>
|
||
<body>
|
||
<header class="site">
|
||
<a class="brand" href="index.html">F1 <span>Circuits</span> API</a>
|
||
<nav aria-label="Examples">
|
||
<a href="index.html">Overview</a>
|
||
<a href="circuits.html">Circuit browser</a>
|
||
<a href="tracks.html">Track images</a>
|
||
<a href="map.html">GPS traces</a>
|
||
<a href="grand-prix.html">Grand prix lookup</a>
|
||
<a href="posters.html" aria-current="page">Posters</a>
|
||
<a href="kometa.html">Kometa</a>
|
||
<a href="library.html">Library</a>
|
||
</nav>
|
||
<div id="api-base"></div>
|
||
</header>
|
||
|
||
<main>
|
||
<h1>Posters</h1>
|
||
<p class="lead">
|
||
The API renders artwork for a Formula 1 library in Plex: a 1000×1500 poster per race and per season, and a
|
||
1920×1080 thumbnail per session of a race weekend. The server draws each one on request, fetching map tiles for its
|
||
background, and keeps it on disk afterwards; so this page renders only the one you ask for, when you press its
|
||
button.
|
||
</p>
|
||
|
||
<section class="card" id="races">
|
||
<h2>1. Choose a race</h2>
|
||
<p>The race poster and the session thumbnails name the race as Jolpica’s <code>raceName</code>; this list comes from Jolpica.</p>
|
||
<div class="controls" id="race-picker"></div>
|
||
<div class="request"></div>
|
||
<div class="status"></div>
|
||
</section>
|
||
|
||
<div class="grid-2">
|
||
<section class="card" id="race-poster">
|
||
<h2>Race poster</h2>
|
||
<p><code>/posters/race/{race name}/{season}.png?bg={background}</code>, 1000×1500: the round, the race’s name, the track and its date over a map of the circuit.</p>
|
||
<div class="controls">
|
||
<label><span>Background (<code>bg</code>)</span>
|
||
<select id="bg">
|
||
<option value="aerial">aerial: Esri satellite imagery (the default)</option>
|
||
<option value="osm">osm: OpenStreetMap street map</option>
|
||
<option value="dark">dark: Esri Dark Gray Canvas</option>
|
||
<option value="light">light: Esri Light Gray Canvas</option>
|
||
<option value="none">none: plain black, no tiles (fastest)</option>
|
||
</select>
|
||
</label>
|
||
<button type="button" class="primary" id="render-race">Render the race poster</button>
|
||
</div>
|
||
<div class="request compact"></div>
|
||
<div class="status idle">Not rendered yet.</div>
|
||
<div class="result preview"></div>
|
||
</section>
|
||
|
||
<section class="card" id="season-poster">
|
||
<h2>Season poster</h2>
|
||
<p><code>/posters/season/{season}.png</code>, 1000×1500: the year over a photo of that season’s cars, or over black when the server has no photo for it.</p>
|
||
<div class="controls">
|
||
<label>Season <input type="number" id="season" min="1950" max="2100"></label>
|
||
<button type="button" class="primary" id="render-season">Render the season poster</button>
|
||
</div>
|
||
<div class="request compact"></div>
|
||
<div class="status idle">Not rendered yet.</div>
|
||
<div class="result preview"></div>
|
||
</section>
|
||
</div>
|
||
|
||
<section class="card" id="session-thumb">
|
||
<h2>Session thumbnail</h2>
|
||
<p>
|
||
<code>/posters/session/{race name}/{season}/{session}.png</code>, 1920×1080: an aerial view of the circuit with
|
||
the race’s name and the session’s label. Kometa numbers a weekend’s episodes differently for a standard weekend
|
||
(10 episodes) and a sprint weekend (15); the list shows the chosen race’s format first, in episode order.
|
||
</p>
|
||
<div class="controls">
|
||
<label><span>Session (<code>session</code>)</span> <select id="session"></select></label>
|
||
<button type="button" class="primary" id="render-session">Render the thumbnail</button>
|
||
</div>
|
||
<div class="request"></div>
|
||
<div class="status idle">Not rendered yet.</div>
|
||
<div class="result preview"></div>
|
||
</section>
|
||
|
||
<h2>Every session slug</h2>
|
||
<table>
|
||
<thead><tr><th>Slug</th><th>Label on the thumbnail</th><th>Episode, standard weekend</th><th>Episode, sprint weekend</th></tr></thead>
|
||
<tbody id="slugs"></tbody>
|
||
</table>
|
||
</main>
|
||
|
||
<footer class="pager">
|
||
<a rel="prev" href="grand-prix.html">← Grand prix lookup</a>
|
||
<a class="home" href="index.html">All examples</a>
|
||
<a rel="next" href="kometa.html">Kometa →</a>
|
||
</footer>
|
||
|
||
<script src="site.js"></script>
|
||
<script>
|
||
(function () {
|
||
const { h, api, path, call, setRequest, setStatus, showImage, racePicker } = F1;
|
||
const $ = (id) => document.getElementById(id);
|
||
|
||
const STANDARD = F1.SESSIONS.standard;
|
||
const SPRINT = F1.SESSIONS.sprint;
|
||
const LABEL = Object.fromEntries([...STANDARD, ...SPRINT]);
|
||
const ALL = Object.keys(LABEL);
|
||
|
||
$('slugs').replaceChildren(...ALL.map((slug) => {
|
||
const std = STANDARD.findIndex(([s]) => s === slug);
|
||
const spr = SPRINT.findIndex(([s]) => s === slug);
|
||
return h('tr', {}, h('td', {}, h('code', {}, slug)), h('td', {}, LABEL[slug]),
|
||
h('td', {}, std >= 0 ? String(std + 1) : '–'), h('td', {}, spr >= 0 ? String(spr + 1) : '–'));
|
||
}));
|
||
|
||
let chosen = null;
|
||
let seasonTouched = false;
|
||
|
||
/** Shows the URL a button will call, without calling it; a result of another URL is cleared. */
|
||
function preview(card, url) {
|
||
card._wanted = url;
|
||
if (card._shown === url) return;
|
||
setRequest(card.querySelector('.request'), url);
|
||
card.querySelector('.result').replaceChildren();
|
||
card._shown = null;
|
||
if (!card.querySelector('.status').classList.contains('pending')) {
|
||
setStatus(card.querySelector('.status'), 'idle', 'Not rendered yet: press the button.');
|
||
}
|
||
}
|
||
|
||
async function render(card, button, url, alt, portrait) {
|
||
button.disabled = true;
|
||
try {
|
||
const answer = await call(card, url, { waiting: 'Rendering on the server: it fetches map tiles first, a few seconds the first time…' });
|
||
const out = card.querySelector('.result');
|
||
if (card._wanted !== url) {
|
||
setRequest(card.querySelector('.request'), card._wanted);
|
||
setStatus(card.querySelector('.status'), 'idle', 'The choice changed while it rendered: press the button again.');
|
||
return;
|
||
}
|
||
if (!answer) { out.replaceChildren(); return; }
|
||
await showImage(out, answer, 'png', { alt, tile: false, className: portrait ? 'poster portrait' : 'poster', status: card.querySelector('.status') });
|
||
card._shown = url;
|
||
} finally {
|
||
button.disabled = false;
|
||
}
|
||
}
|
||
|
||
const raceURL = () => api(path`/posters/race/${chosen.name}/${chosen.season}.png`) + `?bg=${encodeURIComponent($('bg').value)}`;
|
||
const seasonURL = () => api(path`/posters/season/${$('season').value}.png`);
|
||
const sessionURL = () => api(path`/posters/session/${chosen.name}/${chosen.season}/${$('session').value}.png`);
|
||
|
||
function fillSessions() {
|
||
const keep = $('session').value || 'race';
|
||
const own = chosen && chosen.sprint ? SPRINT : STANDARD;
|
||
const ownSlugs = new Set(own.map(([s]) => s));
|
||
const rest = ALL.filter((s) => !ownSlugs.has(s));
|
||
const format = chosen && chosen.race ? (chosen.sprint ? 'a sprint weekend' : 'a standard weekend') : 'format unknown, standard order';
|
||
$('session').replaceChildren(
|
||
h('optgroup', { label: `This race (${format})` },
|
||
...own.map(([s, label], i) => h('option', { value: s }, `Episode ${i + 1} · ${label} (${s})`))),
|
||
h('optgroup', { label: 'The other format’s slugs' },
|
||
...rest.map((s) => h('option', { value: s }, `${LABEL[s]} (${s})`))));
|
||
$('session').value = ALL.includes(keep) ? keep : 'race';
|
||
}
|
||
|
||
function previews() {
|
||
if (chosen && chosen.name) {
|
||
preview($('race-poster'), raceURL());
|
||
preview($('session-thumb'), sessionURL());
|
||
}
|
||
if ($('season').value) preview($('season-poster'), seasonURL());
|
||
}
|
||
|
||
$('bg').addEventListener('change', previews);
|
||
$('session').addEventListener('change', previews);
|
||
$('season').addEventListener('input', () => { seasonTouched = true; previews(); });
|
||
|
||
$('render-race').addEventListener('click', () => {
|
||
if (chosen && chosen.name) render($('race-poster'), $('render-race'), raceURL(), `${chosen.name} ${chosen.season} poster`, true);
|
||
});
|
||
$('render-season').addEventListener('click', () => {
|
||
if ($('season').value) render($('season-poster'), $('render-season'), seasonURL(), `${$('season').value} season poster`, true);
|
||
});
|
||
$('render-session').addEventListener('click', () => {
|
||
if (chosen && chosen.name) render($('session-thumb'), $('render-session'), sessionURL(), `${chosen.name} ${chosen.season} ${$('session').value} thumbnail`, false);
|
||
});
|
||
|
||
racePicker($('race-picker'), {
|
||
card: $('races'),
|
||
onChange: (c) => {
|
||
chosen = c;
|
||
if (!seasonTouched) $('season').value = c.season;
|
||
fillSessions();
|
||
previews();
|
||
},
|
||
});
|
||
})();
|
||
</script>
|
||
</body>
|
||
</html>
|