Files
f1-circuits/examples/circuits.html
T
jschoubben 09a83f6ad9 Guide Plex and Emby users step by step to the posters, at /guides/
People put the posters in their own libraries (one in an automated F1 library in Emby), and
the only help was the Kometa example page, written for developers. The guides are for people
who are not: numbered steps of one action each, the exact menus and buttons of Plex, Kometa and
Emby as their own documentation names them, boxes to copy, the pictures from the live API,
what to see after a step and what to do when it does not work. The technical details (routes,
options, the address version, a script and Emby's API) sit at the end of each.

guides/ holds the index, plex.html (a Plex TV library on the Personal Media Shows agent, Kometa
pointed at /kometa/formula-1-metadata.yml, its daily run) and emby.html (Kometa needs Plex, so:
Set Image from URL by hand, or picture files named as Emby's TV naming page reads them, and a
script that saves a whole season from the Kometa file). They use the example site's style
sheet; every example page's nav links them, and README.md lists them.

cdn-api.py serves guides/ at /guides/ beside /examples/, and the image copies it. A mount of a
directory the image lacks stops the service at its start, so tests/test_image.py holds that
every directory the app serves is copied by service/Dockerfile.
2026-11-30 12:46:36 +01:00

232 lines
10 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Circuit browser · F1 Circuits API examples</title>
<meta name="description" content="Browse the F1 Circuits catalogue: countries, cities, circuits and layouts, with each layout's track image.">
<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" aria-current="page">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">Posters</a>
<a href="builder.html">Poster builder</a>
<a href="kometa.html">Kometa</a>
<a href="library.html">Library</a>
<a href="picker.html">Photo picker</a>
<a href="licences.html">Licences</a>
<a href="../guides/index.html">Guides</a>
</nav>
<div id="api-base"></div>
</header>
<main>
<h1>Circuit browser</h1>
<p class="lead">
The catalogue is a tree: a country holds cities, a city holds circuits, a circuit holds layouts. Each level has a
route; pick an entry to make the next call. Every layout shows its track image.
</p>
<section class="card" id="countries">
<h2>1. Countries</h2>
<p><code>/circuits</code> lists every country, and nests its whole tree inside each one.</p>
<div class="request"></div>
<div class="status"></div>
<div class="choices" id="country-list"></div>
<details><summary>The JSON answer</summary><div class="result"></div></details>
</section>
<section class="card" id="cities">
<h2>2. Cities of a country</h2>
<p><code>/circuits/{country}</code> answers <code>{"cities": [...]}</code>, each city with its circuits.</p>
<div class="request"></div>
<div class="status idle">Pick a country above.</div>
<div class="choices" id="city-list"></div>
<details><summary>The JSON answer</summary><div class="result"></div></details>
</section>
<section class="card" id="circuits">
<h2>3. Circuits in a city</h2>
<p><code>/circuits/{country}/{city}</code> answers <code>{"circuits": [...]}</code>.</p>
<div class="request"></div>
<div class="status idle">Pick a city above.</div>
<div class="choices" id="circuit-list"></div>
<details><summary>The JSON answer</summary><div class="result"></div></details>
</section>
<section class="card" id="circuit">
<h2>4. One circuit and its layouts</h2>
<p>
<code>/circuits/{country}/{city}/{circuit}</code> answers the circuit’s name, its Wikipedia and Fandom pages and
its layouts. Each layout’s image below is its own call,
<code>/circuits/{country}/{city}/{circuit}/layout/{layout}/svg</code> (see <a href="tracks.html">Track images</a>).
</p>
<div class="request"></div>
<div class="status idle">Pick a circuit above.</div>
<div id="circuit-head"></div>
<div class="layouts" id="layout-list"></div>
<details><summary>The JSON answer</summary><div class="result"></div></details>
</section>
<section class="card" id="layout">
<h2>5. One layout</h2>
<p>
<code>/circuits/{country}/{city}/{circuit}/layout/{layout}</code> answers one layout: its slug, its description
and <code>imageUrl</code>, the source drawing on the F1 Fandom wiki.
</p>
<div class="request"></div>
<div class="status idle" data-idle="Press “Details” on a layout above.">Press “Details” on a layout above.</div>
<div class="result"></div>
</section>
</main>
<footer class="pager">
<a rel="prev" href="index.html">← Overview</a>
<a class="home" href="index.html">All examples</a>
<a rel="next" href="tracks.html">Track images →</a>
</footer>
<footer class="disclaimer">
<p>This website is unofficial and is not associated in any way with the Formula 1 companies. F1, FORMULA ONE,
FORMULA 1, FIA FORMULA ONE WORLD CHAMPIONSHIP, GRAND PRIX and related marks are trade marks of Formula One
Licensing B.V.</p>
<p><a href="licences.html">Licences and credits</a>: every source the pictures are made from, the licence each
picture takes from its sources, and the licence of the track files and the GPS traces (MIT).</p>
</footer>
<script src="site.js"></script>
<script>
(function () {
const { h, api, path, callJSON, setRequest, layoutYears, layoutStart } = F1;
const $ = (id) => document.getElementById(id);
const want = {
country: F1.params.get('country') || 'belgium',
city: F1.params.get('city') || 'spa',
circuit: F1.params.get('circuit') || 'circuit-de-spa-francorchamps',
};
const state = {};
function remember() {
const url = new URL(location.href);
for (const k of ['country', 'city', 'circuit']) {
if (state[k]) url.searchParams.set(k, state[k]); else url.searchParams.delete(k);
}
history.replaceState(null, '', url.href);
}
function choices(el, items, pressed, onPick) {
el.replaceChildren(...items.map((it) => {
const b = h('button', { type: 'button', 'aria-pressed': String(it.slug === pressed), title: `slug: ${it.slug}` },
it.name, ' ', h('small', {}, it.note));
b.addEventListener('click', () => {
for (const o of el.querySelectorAll('button')) o.setAttribute('aria-pressed', String(o === b));
onPick(it.slug);
});
return b;
}));
}
function clear(...ids) {
for (const id of ids) {
const card = $(id);
card.querySelector('.request').replaceChildren();
const s = card.querySelector('.status');
s.className = 'status idle';
s.textContent = s.dataset.idle || 'Pick an entry above.';
card.querySelector('.result').replaceChildren();
}
if (ids.includes('cities')) $('city-list').replaceChildren();
if (ids.includes('circuits')) $('circuit-list').replaceChildren();
if (ids.includes('circuit')) { $('circuit-head').replaceChildren(); $('layout-list').replaceChildren(); }
}
const byName = (a, b) => a.name.localeCompare(b.name);
const count = (n, one, many) => `${n} ${n === 1 ? one : many}`;
async function loadCountries() {
const v = await callJSON($('countries'), api('/circuits'));
if (!v) return;
const list = [...v.countries].sort(byName);
choices($('country-list'), list.map((c) => ({ slug: c.slug, name: c.name, note: count(Object.keys(c.localities).length, 'city', 'cities') })),
want.country, pickCountry);
if (list.some((c) => c.slug === want.country)) pickCountry(want.country);
}
async function pickCountry(slug) {
state.country = slug; state.city = state.circuit = null; remember();
clear('cities', 'circuits', 'circuit', 'layout');
const v = await callJSON($('cities'), api(path`/circuits/${slug}`));
if (!v) return;
const list = [...v.cities].sort(byName);
choices($('city-list'), list.map((c) => ({ slug: c.slug, name: c.name, note: count(Object.keys(c.circuits).length, 'circuit', 'circuits') })),
want.city, pickCity);
const next = list.find((c) => c.slug === want.city) || (list.length === 1 ? list[0] : null);
if (next) { $('city-list').querySelector(`[title="slug: ${CSS.escape(next.slug)}"]`).setAttribute('aria-pressed', 'true'); pickCity(next.slug); }
}
async function pickCity(slug) {
state.city = slug; state.circuit = null; remember();
clear('circuits', 'circuit', 'layout');
const v = await callJSON($('circuits'), api(path`/circuits/${state.country}/${slug}`));
if (!v) return;
const list = [...v.circuits].sort(byName);
choices($('circuit-list'), list.map((c) => ({ slug: c.slug, name: c.name, note: count(Object.keys(c.layouts).length, 'layout', 'layouts') })),
want.circuit, pickCircuit);
const next = list.find((c) => c.slug === want.circuit) || (list.length === 1 ? list[0] : null);
if (next) { $('circuit-list').querySelector(`[title="slug: ${CSS.escape(next.slug)}"]`).setAttribute('aria-pressed', 'true'); pickCircuit(next.slug); }
}
async function pickCircuit(slug) {
state.circuit = slug; remember();
clear('circuit', 'layout');
const { country, city } = state;
const v = await callJSON($('circuit'), api(path`/circuits/${country}/${city}/${slug}`));
if (!v) return;
$('circuit-head').replaceChildren(
h('h3', {}, v.name),
h('p', {}, 'Read more: ',
v.urls.wikipedia ? h('a', { href: v.urls.wikipedia, target: '_blank', rel: 'noopener' }, 'Wikipedia') : null,
v.urls.wikipedia && v.urls.fandom ? ' · ' : null,
v.urls.fandom ? h('a', { href: v.urls.fandom, target: '_blank', rel: 'noopener' }, 'F1 Fandom wiki') : null));
const slugs = Object.keys(v.layouts).sort((a, b) => layoutStart(a) - layoutStart(b));
$('layout-list').replaceChildren(...slugs.map((l) => layoutCard(country, city, slug, v.layouts[l])));
}
function layoutCard(country, city, circuit, layout) {
const imgUrl = api(path`/circuits/${country}/${city}/${circuit}/layout/${layout.slug}/svg`);
const req = h('div', { class: 'request compact' });
setRequest(req, imgUrl);
const img = h('img', { src: imgUrl, alt: `Track layout ${layoutYears(layout.slug)}`, loading: 'lazy' });
const tile = h('div', { class: 'track-tile' }, img);
img.addEventListener('error', () => tile.replaceChildren(F1.notice('error', 'The image did not load; open its URL to see why.')));
const q = new URLSearchParams({ country, city, circuit, layout: layout.slug }).toString();
const details = h('button', { type: 'button' }, 'Details');
details.addEventListener('click', () => {
callJSON($('layout'), api(path`/circuits/${country}/${city}/${circuit}/layout/${layout.slug}`));
$('layout').scrollIntoView({ behavior: 'smooth', block: 'start' });
});
return h('div', { class: 'layout-card' },
h('h3', {}, layoutYears(layout.slug), ' ', h('small', {}, h('code', {}, layout.slug))),
tile,
req,
h('p', {}, layout.description || 'No description.'),
h('div', { class: 'links' },
details,
h('a', { href: F1.linkWithKept(`tracks.html?${q}`) }, 'All formats'),
h('a', { href: F1.linkWithKept(`map.html?${q}`) }, 'On the map'),
layout.imageUrl ? h('a', { href: layout.imageUrl, target: '_blank', rel: 'noopener' }, 'Source drawing') : null));
}
loadCountries();
})();
</script>
</body>
</html>