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
106 lines
4.3 KiB
HTML
106 lines
4.3 KiB
HTML
<!doctype html>
|
||
<html lang="en">
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||
<title>Grand prix lookup · F1 Circuits API examples</title>
|
||
<meta name="description" content="Look up the track of any F1 race by its name and season: the API finds the circuit and the layout raced that year.">
|
||
<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" aria-current="page">Grand prix lookup</a>
|
||
<a href="posters.html">Posters</a>
|
||
<a href="kometa.html">Kometa</a>
|
||
<a href="library.html">Library</a>
|
||
</nav>
|
||
<div id="api-base"></div>
|
||
</header>
|
||
|
||
<main>
|
||
<h1>Grand prix lookup</h1>
|
||
<p class="lead">
|
||
Name a race and a season, and the API answers the track it was raced on: it reads that season’s schedule from
|
||
Jolpica, matches the race by its exact name, finds the circuit in its catalogue and picks the layout of that year.
|
||
</p>
|
||
|
||
<section class="card" id="races">
|
||
<h2>1. The season’s races</h2>
|
||
<p>
|
||
This page lists the races by calling Jolpica itself, from the browser (Jolpica allows any origin). If it cannot
|
||
be reached, type the name: the API needs it exactly as Jolpica’s <code>raceName</code>, such as
|
||
<code>British Grand Prix</code>.
|
||
</p>
|
||
<div class="controls" id="race-picker"></div>
|
||
<div class="request"></div>
|
||
<div class="status"></div>
|
||
</section>
|
||
|
||
<section class="card" id="lookup">
|
||
<h2>2. The race’s track</h2>
|
||
<p><code>/grand-prix/{race name}/{season}/{format}</code>, the race name percent-encoded (a space is <code>%20</code>).</p>
|
||
<div class="controls"><fieldset id="format"><legend>Format</legend></fieldset></div>
|
||
<div id="jolpica-says"></div>
|
||
<div class="request"></div>
|
||
<div class="status idle">Choose a race.</div>
|
||
<div class="result"></div>
|
||
</section>
|
||
|
||
<h2>When the lookup finds nothing</h2>
|
||
<p>
|
||
The API answers <code>404 {"detail": "Circuit not found"}</code> when the name is not in that season’s schedule,
|
||
when Jolpica cannot be reached from the server, or when the circuit or that year’s layout is not in the catalogue
|
||
yet (browse it in the <a href="circuits.html">circuit browser</a>).
|
||
</p>
|
||
</main>
|
||
|
||
<footer class="pager">
|
||
<a rel="prev" href="map.html">← GPS traces</a>
|
||
<a class="home" href="index.html">All examples</a>
|
||
<a rel="next" href="posters.html">Posters →</a>
|
||
</footer>
|
||
|
||
<script src="site.js"></script>
|
||
<script>
|
||
(function () {
|
||
const { h, api, path, call, showImage, showGeoJSON, racePicker } = F1;
|
||
const $ = (id) => document.getElementById(id);
|
||
const card = $('lookup');
|
||
const FORMATS = ['svg', 'png', 'geojson'];
|
||
const initial = FORMATS.includes(F1.params.get('format')) ? F1.params.get('format') : 'svg';
|
||
for (const f of FORMATS) {
|
||
const input = h('input', { type: 'radio', name: 'format', value: f, checked: f === initial });
|
||
input.addEventListener('change', lookup);
|
||
$('format').append(h('label', { class: 'inline' }, input, f));
|
||
}
|
||
|
||
let chosen = null;
|
||
|
||
async function lookup() {
|
||
if (!chosen || !chosen.name || !(chosen.season >= 1950)) return;
|
||
const f = $('format').querySelector('input:checked').value;
|
||
const r = chosen.race;
|
||
$('jolpica-says').replaceChildren(r
|
||
? h('p', {}, `Jolpica: round ${r.round} on ${r.date}, at ${r.Circuit.circuitName} in ${r.Circuit.Location.locality}, ${r.Circuit.Location.country}.`)
|
||
: h('p', {}, 'Jolpica’s entry for this name is not known on this page; the API looks it up itself.'));
|
||
const answer = await call(card, api(path`/grand-prix/${chosen.name}/${chosen.season}/${f}`), { waiting: 'Looking up the race…' });
|
||
const out = card.querySelector('.result');
|
||
if (!answer) { out.replaceChildren(); return; }
|
||
const status = card.querySelector('.status');
|
||
if (f === 'geojson') await showGeoJSON(out, answer, { status });
|
||
else await showImage(out, answer, f, { alt: `${chosen.name} ${chosen.season}`, status });
|
||
}
|
||
|
||
racePicker($('race-picker'), { card: $('races'), onChange: (c) => { chosen = c; lookup(); } });
|
||
})();
|
||
</script>
|
||
</body>
|
||
</html>
|