Add the photo picker, poster builder and licences pages
A pick is a repository edit, so the picker shows the Commons candidates cropped to the poster's frame, natural or bw as the service treats them, beside the picks of the circuit's other layouts, and gives the entry to copy (the picks file's "$comment" kept first). The builder sends every option of docs/posters.md as a query parameter, renders only on request and shows the answer's X-Credits and X-License. The licences page shows /licences: each source, its credit and the licence a picture made from it gets. Every page now carries the Formula 1 disclaimer at its foot, as F1's guidelines ask of an unofficial site, and the posters page lists the backgrounds the design keeps (no Esri). Claude-Session: https://claude.ai/code/session_01NcbgfJAa38xFpzy69BWrqh
This commit is contained in:
@@ -0,0 +1,519 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Photo picker · F1 Circuits API examples</title>
|
||||
<meta name="description" content="Pick a freely licensed Wikimedia Commons photo per circuit layout and per season for the F1 Circuits posters, and copy its entry for the picks file.">
|
||||
<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">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" aria-current="page">Photo picker</a>
|
||||
<a href="licences.html">Licences</a>
|
||||
</nav>
|
||||
<div id="api-base"></div>
|
||||
</header>
|
||||
|
||||
<!-- bw as the service draws it: Pillow's convert("L"), L = 0.299 R + 0.587 G + 0.114 B on the sRGB values. -->
|
||||
<svg width="0" height="0" style="position:absolute" aria-hidden="true" focusable="false">
|
||||
<filter id="bw" color-interpolation-filters="sRGB">
|
||||
<feColorMatrix type="matrix" values="0.299 0.587 0.114 0 0 0.299 0.587 0.114 0 0 0.299 0.587 0.114 0 0 0 0 0 1 0"/>
|
||||
</filter>
|
||||
</svg>
|
||||
|
||||
<main>
|
||||
<h1>Photo picker</h1>
|
||||
<p class="lead">
|
||||
A race poster over <code>bg=satellite</code> uses a layout’s picked Wikimedia Commons photo when it has one, and a
|
||||
season poster shows that season’s cars only from a picked photo. This page shows the candidates
|
||||
<code>tools/commons_candidates.py</code> found, cropped to the poster’s frame as the service crops them, in natural
|
||||
colour or black and white. Choosing one gives the entry to copy into the picks file. The page writes nothing to the
|
||||
server: a pick is a change to the repository.
|
||||
</p>
|
||||
<p>
|
||||
Only CC0, public domain, CC BY and CC BY-SA files are listed, with Commons’ quality marks first, then size, then
|
||||
landscape. A search also finds ground photos, maps and the odd helicopter, so look at each one before you pick it.
|
||||
</p>
|
||||
|
||||
<section class="card" id="files">
|
||||
<h2>1. The lists</h2>
|
||||
<p class="hint">The candidates come with the site; the picks are read from the repository, beside the page’s folder.
|
||||
Run <code>python3 -m http.server</code> in the working copy and open <code>/examples/picker.html</code> there to
|
||||
have both, or load a picks file from disk below.</p>
|
||||
<div id="cand-file">
|
||||
<div class="request"></div>
|
||||
<div class="status"></div>
|
||||
<div class="result"></div>
|
||||
</div>
|
||||
<div id="picks-circuits">
|
||||
<div class="request"></div>
|
||||
<div class="status"></div>
|
||||
<div class="result"></div>
|
||||
</div>
|
||||
<div id="picks-seasons">
|
||||
<div class="request"></div>
|
||||
<div class="status"></div>
|
||||
<div class="result"></div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="card" id="choose">
|
||||
<h2>2. What to pick for</h2>
|
||||
<div class="controls">
|
||||
<label><span>Pick for</span>
|
||||
<span class="seg" id="mode">
|
||||
<button type="button" data-v="layout">A layout</button><button type="button" data-v="season">A season</button>
|
||||
</span>
|
||||
</label>
|
||||
<label><span>Photo (<code>photo</code>)</span>
|
||||
<span class="seg" id="treat">
|
||||
<button type="button" data-v="natural">natural</button><button type="button" data-v="bw">bw</button>
|
||||
</span>
|
||||
</label>
|
||||
<label id="frame-label"><span>Frame</span>
|
||||
<span class="seg" id="frame">
|
||||
<button type="button" data-v="poster">poster 1000×1500</button><button type="button" data-v="thumb">thumbnail 1920×1080</button>
|
||||
</span>
|
||||
</label>
|
||||
</div>
|
||||
<div class="controls" id="layout-picker"></div>
|
||||
<div class="controls" id="season-picker" hidden>
|
||||
<label>Season <select id="season" aria-label="Season"></select></label>
|
||||
</div>
|
||||
<div class="request"></div>
|
||||
<div class="status"></div>
|
||||
<div class="result"></div>
|
||||
</section>
|
||||
|
||||
<section class="card" id="entry" hidden>
|
||||
<h2>3. The entry to copy</h2>
|
||||
<div id="entry-body"></div>
|
||||
</section>
|
||||
|
||||
<div id="photos-root">
|
||||
<h2 id="others-title">Picks of the circuit’s other layouts</h2>
|
||||
<div id="others"></div>
|
||||
<h2 id="cands-title">Candidates</h2>
|
||||
<div id="cands"></div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<footer class="pager">
|
||||
<a rel="prev" href="library.html">← Library</a>
|
||||
<a class="home" href="index.html">All examples</a>
|
||||
<a rel="next" href="licences.html">Licences →</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, notice, setRequest, setStatus, showJSON, layoutPicker, layoutYears, params } = F1;
|
||||
const $ = (id) => document.getElementById(id);
|
||||
|
||||
const FRAMES = { poster: [1000, 1500], thumb: [1920, 1080] };
|
||||
const PICK_FIELDS = ['file', 'licence', 'author', 'credit', 'date'];
|
||||
const FILES = {
|
||||
candidates: { card: $('cand-file'), url: 'data/candidates.json', what: 'the candidates (examples/data/candidates.json)' },
|
||||
circuits: { card: $('picks-circuits'), url: '../circuits/photos.json', what: 'the layouts’ picks (circuits/photos.json)' },
|
||||
seasons: { card: $('picks-seasons'), url: '../seasons/photos.json', what: 'the seasons’ picks (seasons/photos.json)' },
|
||||
};
|
||||
|
||||
const state = {
|
||||
mode: params.get('mode') === 'season' ? 'season' : 'layout',
|
||||
treat: params.get('photo') === 'bw' ? 'bw' : 'natural',
|
||||
frame: params.get('frame') === 'thumb' ? 'thumb' : 'poster',
|
||||
candidates: null,
|
||||
picks: { circuits: null, seasons: null },
|
||||
pick: null, // the layout picker's choice
|
||||
chosen: null, // { key, cand }
|
||||
};
|
||||
|
||||
function syncURL() {
|
||||
const url = new URL(location.href);
|
||||
url.searchParams.set('mode', state.mode);
|
||||
url.searchParams.set('photo', state.treat);
|
||||
url.searchParams.set('frame', state.frame);
|
||||
if (state.mode === 'season' && $('season').value) url.searchParams.set('season', $('season').value);
|
||||
history.replaceState(null, '', url.href);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------ the three files
|
||||
|
||||
/** A picks file read: an object of entries; keys starting with "$" (the format note) are kept but are no pick. */
|
||||
function validPicks(value) {
|
||||
if (!value || typeof value !== 'object' || Array.isArray(value)) return 'it is not a JSON object';
|
||||
for (const [k, v] of Object.entries(value)) {
|
||||
if (k.startsWith('$')) continue;
|
||||
if (!v || typeof v !== 'object' || typeof v.file !== 'string') return `its entry “${k}” has no file`;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
function validCandidates(value) {
|
||||
if (!value || typeof value !== 'object' || !value.layouts || !value.seasons) return 'it has no layouts and seasons';
|
||||
return '';
|
||||
}
|
||||
|
||||
/** Reads one file over http, or offers to load it from disk when that fails; calls done(value) once read. */
|
||||
async function readFile(name, done) {
|
||||
const f = FILES[name];
|
||||
const card = f.card;
|
||||
const out = card.querySelector('.result');
|
||||
const url = new URL(f.url, location.href).href;
|
||||
setRequest(card.querySelector('.request'), url, name === 'candidates' ? 'a file of the site, not the API' : 'a file of the repository, not the API');
|
||||
setStatus(card.querySelector('.status'), 'pending', `Reading ${f.what}…`);
|
||||
const check = name === 'candidates' ? validCandidates : validPicks;
|
||||
let why = '';
|
||||
try {
|
||||
const res = await fetch(url, { cache: 'no-cache' });
|
||||
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
||||
const value = JSON.parse(await res.text());
|
||||
why = check(value);
|
||||
if (!why) {
|
||||
accept(name, value, `Read ${f.what} from ${url}.`);
|
||||
done(value);
|
||||
return;
|
||||
}
|
||||
} catch (e) {
|
||||
why = e instanceof SyntaxError ? 'it is not JSON' : e.message;
|
||||
}
|
||||
setStatus(card.querySelector('.status'), 'error', `Could not read ${f.what}: ${why}.`);
|
||||
const input = h('input', { type: 'file', accept: '.json,application/json' });
|
||||
input.addEventListener('change', async () => {
|
||||
const file = input.files && input.files[0];
|
||||
if (!file) return;
|
||||
try {
|
||||
const value = JSON.parse(await file.text());
|
||||
const bad = check(value);
|
||||
if (bad) { setStatus(card.querySelector('.status'), 'error', `${file.name}: ${bad}.`); return; }
|
||||
accept(name, value, `Loaded ${f.what} from disk (${file.name}).`);
|
||||
done(value);
|
||||
} catch (e) {
|
||||
setStatus(card.querySelector('.status'), 'error', `${file.name} is not JSON: ${e.message}`);
|
||||
}
|
||||
});
|
||||
out.replaceChildren(notice('error',
|
||||
name === 'candidates'
|
||||
? 'Without the candidates there is nothing to show. '
|
||||
: 'Without the picks file the page cannot show what is picked, nor the whole file with a new pick. ',
|
||||
'The page reads it relative to itself; served by the API only /examples/ is there. Load it from disk: ', input));
|
||||
}
|
||||
|
||||
function accept(name, value, text) {
|
||||
const f = FILES[name];
|
||||
const card = f.card;
|
||||
setStatus(card.querySelector('.status'), 'ok', text);
|
||||
const out = card.querySelector('.result');
|
||||
if (name === 'candidates') {
|
||||
const ls = Object.values(value.layouts);
|
||||
const ss = Object.values(value.seasons);
|
||||
const about = value.about || {};
|
||||
out.replaceChildren(h('p', { class: 'hint' },
|
||||
`${ls.filter((l) => l.length).length} of ${ls.length} layouts and ${ss.filter((s) => s.length).length} of ${ss.length} seasons have at least one candidate. `,
|
||||
about.made ? `Listed ${about.made.replace('T', ' ').replace('+00:00', ' UTC')}` : '',
|
||||
about.requests ? ` with ${about.requests} requests to Commons.` : '.'));
|
||||
} else {
|
||||
const n = Object.keys(value).filter((k) => !k.startsWith('$')).length;
|
||||
out.replaceChildren(h('p', { class: 'hint' }, `${n} pick${n === 1 ? '' : 's'} so far.`,
|
||||
value.$comment ? h('span', {}, ' Its note: ', h('em', {}, String(value.$comment))) : ''));
|
||||
}
|
||||
if (name === 'candidates') state.candidates = value; else state.picks[name] = value;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------ cards
|
||||
|
||||
/** Commons' thumbnail of a file: from the candidates when listed, else its standard 500-px thumbnail address. */
|
||||
function thumbOf(file) {
|
||||
const c = state.candidates;
|
||||
if (c) {
|
||||
for (const list of [...Object.values(c.layouts), ...Object.values(c.seasons)]) {
|
||||
const hit = list.find((x) => x.file === file);
|
||||
if (hit) return hit.thumb;
|
||||
}
|
||||
}
|
||||
return `https://commons.wikimedia.org/wiki/Special:FilePath/${encodeURIComponent(file)}?width=500`;
|
||||
}
|
||||
|
||||
function pageOf(file) { return `https://commons.wikimedia.org/wiki/File:${encodeURIComponent(file.replace(/ /g, '_'))}`; }
|
||||
|
||||
/** How much the service scales a photo up to cover the frame, when it does. */
|
||||
function scaleUp(c) {
|
||||
const [fw, fh] = FRAMES[frameNow()];
|
||||
if (!c.width || !c.height) return 0;
|
||||
const s = Math.max(fw / c.width, fh / c.height);
|
||||
return s > 1 ? s : 0;
|
||||
}
|
||||
|
||||
function frameNow() { return state.mode === 'season' ? 'poster' : state.frame; }
|
||||
|
||||
function photoCard(c, opts = {}) {
|
||||
const up = scaleUp(c);
|
||||
const tags = [
|
||||
...(c.marks || []).map((m) => h('span', { class: 'tag mark', title: 'A Commons quality mark' }, m)),
|
||||
...(c.restrictions || []).map((r) => h('span', { class: 'tag warn', title: 'A right beside copyright the file names' }, `${r} rights`)),
|
||||
up ? h('span', { class: 'tag warn', title: 'Smaller than the frame: the service scales it up' }, `scaled up ×${up.toFixed(1)}`) : null,
|
||||
].filter(Boolean);
|
||||
const chosen = opts.choose && state.chosen && state.chosen.cand.file === c.file;
|
||||
const card = h('article', { class: `photo-card${opts.picked ? ' picked' : ''}${chosen ? ' chosen' : ''}` },
|
||||
h('div', { class: 'photo-frame' },
|
||||
h('img', { src: c.thumb || thumbOf(c.file), alt: c.file, loading: 'lazy', decoding: 'async', referrerpolicy: 'no-referrer' })),
|
||||
opts.label ? h('div', { class: 'meta' }, h('b', {}, opts.label)) : null,
|
||||
h('div', { class: 'name' }, c.file),
|
||||
h('div', { class: 'meta' },
|
||||
h('b', {}, c.date || 'undated'),
|
||||
c.width ? ` · ${c.width}×${c.height}` : '',
|
||||
' · ', c.licence_url ? h('a', { href: c.licence_url, target: '_blank', rel: 'noopener' }, c.licence) : c.licence,
|
||||
h('br'), c.author),
|
||||
tags.length ? h('div', { class: 'tags' }, ...tags) : null,
|
||||
c.found ? h('div', { class: 'meta', title: 'How the tool found it' },
|
||||
`Found by ${c.found.map((f) => (f === 'marked' ? 'a search for its category’s quality-marked files' : f)).join('; ')}`) : null,
|
||||
h('div', { class: 'actions' },
|
||||
opts.choose ? h('button', { type: 'button', class: 'primary', onclick: () => opts.choose(card) }, 'Choose') : null,
|
||||
h('a', { href: c.page || pageOf(c.file), target: '_blank', rel: 'noopener' }, 'On Commons')));
|
||||
return card;
|
||||
}
|
||||
|
||||
function grid(cards, extra = '') {
|
||||
const cls = `photos${frameNow() === 'thumb' ? ' thumb' : ''}${extra ? ` ${extra}` : ''}`;
|
||||
return h('div', { class: cls }, ...cards);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------ the entry to copy
|
||||
|
||||
function entryOf(c) {
|
||||
const e = {};
|
||||
for (const k of PICK_FIELDS) e[k] = c[k] === undefined ? null : c[k];
|
||||
return e;
|
||||
}
|
||||
|
||||
/**
|
||||
* The picks file's text with one entry set: its "$" keys first as they stand, then every pick by key. Written from
|
||||
* a list of pairs, not an object: an object lists keys such as "2024" before "$comment", whatever their order.
|
||||
*/
|
||||
function withPick(file, key, entry) {
|
||||
const notes = Object.entries(file).filter(([k]) => k.startsWith('$'));
|
||||
const picks = new Map(Object.entries(file).filter(([k]) => !k.startsWith('$')));
|
||||
picks.set(key, entry);
|
||||
const sorted = [...picks.keys()].sort((a, b) => a.localeCompare(b, 'en', { numeric: true })).map((k) => [k, picks.get(k)]);
|
||||
const pairs = [...notes, ...sorted];
|
||||
const indent = (text) => text.replace(/\n/g, '\n ');
|
||||
return pairs.length
|
||||
? `{\n${pairs.map(([k, v]) => ` ${JSON.stringify(k)}: ${indent(JSON.stringify(v, null, 2))}`).join(',\n')}\n}`
|
||||
: '{}';
|
||||
}
|
||||
|
||||
function copyBlock(title, text) {
|
||||
const button = h('button', { type: 'button' }, 'Copy');
|
||||
button.addEventListener('click', async () => {
|
||||
try { await navigator.clipboard.writeText(text); button.textContent = 'Copied'; } catch { button.textContent = 'Select and copy'; }
|
||||
setTimeout(() => { button.textContent = 'Copy'; }, 1500);
|
||||
});
|
||||
const body = h('div');
|
||||
showJSON(body, text);
|
||||
return h('div', { class: 'copy-block' }, h('div', { class: 'head' }, h('span', {}, title), button), body);
|
||||
}
|
||||
|
||||
function showEntry() {
|
||||
const section = $('entry');
|
||||
const body = $('entry-body');
|
||||
if (!state.chosen) { section.hidden = true; return; }
|
||||
const { key, cand, fileName, fileKey } = state.chosen;
|
||||
const entry = entryOf(cand);
|
||||
const fragment = `${JSON.stringify(key)}: ${JSON.stringify(entry, null, 2)}`;
|
||||
const parts = [
|
||||
h('p', {}, 'For ', h('code', {}, key), ': ', h('b', {}, cand.file), '. Copy the entry into ', h('code', {}, fileName),
|
||||
', or the whole file below with the entry in place.'),
|
||||
copyBlock(`The entry, for ${fileName}`, fragment),
|
||||
];
|
||||
const sa = /\bBY-SA\b/i.test(cand.licence);
|
||||
parts.push(notice('info', sa
|
||||
? `${cand.licence} is share-alike: a poster made from it is adapted material, shared under CC BY-SA terms. Such a poster is CC BY-SA 4.0.`
|
||||
: `A poster made from it is CC BY 4.0: a picture’s licence follows its sources, and ${cand.licence} asks no share-alike.`,
|
||||
' ', h('a', { href: F1.linkWithKept('licences.html') }, 'The licences page'), ' states the rule.'));
|
||||
if ((cand.restrictions || []).length) {
|
||||
parts.push(notice('', `Commons names ${cand.restrictions.join(' and ')} rights for this file: rights beside its copyright licence, such as a person’s likeness or a trade mark shown in it.`));
|
||||
}
|
||||
const file = state.picks[fileKey];
|
||||
if (file) parts.push(copyBlock(`The whole of ${fileName} with this pick`, withPick(file, key, entry)));
|
||||
else parts.push(notice('error', `${fileName} was not read, so the whole file cannot be shown: copy the entry, or load the file from disk above.`));
|
||||
body.replaceChildren(...parts);
|
||||
section.hidden = false;
|
||||
}
|
||||
|
||||
function choose(key, cand, card, fileName, fileKey) {
|
||||
for (const el of document.querySelectorAll('.photo-card.chosen')) el.classList.remove('chosen');
|
||||
card.classList.add('chosen');
|
||||
state.chosen = { key, cand, fileName, fileKey, mode: state.mode };
|
||||
showEntry();
|
||||
$('entry').scrollIntoView({ behavior: 'smooth', block: 'start' });
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------ rendering a layout or a season
|
||||
|
||||
function picksOf(name) {
|
||||
const file = state.picks[name];
|
||||
return file ? Object.fromEntries(Object.entries(file).filter(([k]) => !k.startsWith('$'))) : null;
|
||||
}
|
||||
|
||||
function render() {
|
||||
syncURL();
|
||||
$('photos-root').className = state.treat === 'bw' ? 'treat-bw' : '';
|
||||
$('frame-label').hidden = state.mode === 'season';
|
||||
$('layout-picker').hidden = state.mode !== 'layout';
|
||||
$('season-picker').hidden = state.mode !== 'season';
|
||||
// The /circuits call fills the layout picker only.
|
||||
for (const sel of ['.request', '.status', '.result']) $('choose').querySelector(`:scope > ${sel}`).hidden = state.mode !== 'layout';
|
||||
for (const [id, v] of [['mode', state.mode], ['treat', state.treat], ['frame', state.frame]]) {
|
||||
for (const b of $(id).querySelectorAll('button')) b.setAttribute('aria-pressed', String(b.dataset.v === v));
|
||||
}
|
||||
if (state.chosen && state.chosen.mode !== state.mode) { state.chosen = null; showEntry(); }
|
||||
if (!state.candidates) {
|
||||
$('others-title').hidden = true;
|
||||
$('others').replaceChildren();
|
||||
$('cands-title').textContent = 'Candidates';
|
||||
$('cands').replaceChildren(notice('error', 'The candidates were not read (see 1).'));
|
||||
return;
|
||||
}
|
||||
if (state.mode === 'layout') renderLayout(); else renderSeason();
|
||||
}
|
||||
|
||||
function renderLayout() {
|
||||
const p = state.pick;
|
||||
if (!p || !p.layout) return;
|
||||
const circuitKey = `${p.country}/${p.city}/${p.circuit}`;
|
||||
const key = `${circuitKey}/${p.layout}`;
|
||||
const picks = picksOf('circuits');
|
||||
const list = state.candidates.layouts[key];
|
||||
const current = picks && picks[key];
|
||||
|
||||
// The circuit's other layouts, and this one's pick when it has one.
|
||||
$('others-title').hidden = false;
|
||||
$('others-title').textContent = `Picks of ${p.circuitName || 'this circuit'}’s layouts`;
|
||||
if (!picks) {
|
||||
$('others').replaceChildren(notice('error', 'circuits/photos.json was not read (see 1), so the picks are not shown.'));
|
||||
} else {
|
||||
const cards = p.layouts.filter((l) => picks[`${circuitKey}/${l}`]).map((l) => {
|
||||
const k = `${circuitKey}/${l}`;
|
||||
const label = `${layoutYears(l)}${l === p.layout ? ' (this layout, picked now)' : ''}`;
|
||||
return photoCard({ ...picks[k], thumb: thumbOf(picks[k].file) }, { label, picked: l === p.layout });
|
||||
});
|
||||
$('others').replaceChildren(cards.length ? grid(cards, 'small')
|
||||
: h('p', { class: 'hint' }, `None of its ${p.layouts.length} layout${p.layouts.length === 1 ? '' : 's'} has a pick yet.`));
|
||||
}
|
||||
|
||||
const undated = ((state.candidates.about || {}).undated_per_circuit || {})[circuitKey];
|
||||
$('cands-title').textContent = `Candidates for ${layoutYears(p.layout)}${list ? ` (${list.length})` : ''}`;
|
||||
if (!list) {
|
||||
$('cands').replaceChildren(notice('error', `The candidates file has no entry for ${key}: run tools/commons_candidates.py again.`));
|
||||
return;
|
||||
}
|
||||
const why = undated ? ` The tool found ${undated} more photo${undated === 1 ? '' : 's'} of this circuit with no date it can read; a layout lists only photos dated within its years.` : '';
|
||||
if (!list.length) {
|
||||
$('cands').replaceChildren(notice('', `Commons has no freely licensed aerial photo of this circuit dated ${layoutYears(p.layout)} that the tool found. Without a pick, bg=satellite uses the national aerial photo, then EOxCloudless.${why}`));
|
||||
return;
|
||||
}
|
||||
state.chosen = state.chosen && state.chosen.key === key ? state.chosen : null;
|
||||
$('cands').replaceChildren(
|
||||
why ? h('p', { class: 'hint' }, why.trim()) : '',
|
||||
grid(list.map((c) => photoCard(c, {
|
||||
picked: current && current.file === c.file,
|
||||
label: current && current.file === c.file ? 'Picked now' : null,
|
||||
choose: (card) => choose(key, c, card, 'circuits/photos.json', 'circuits'),
|
||||
}))));
|
||||
if (!state.chosen) showEntry();
|
||||
}
|
||||
|
||||
function renderSeason() {
|
||||
const year = $('season').value;
|
||||
if (!year) return;
|
||||
const picks = picksOf('seasons');
|
||||
const list = state.candidates.seasons[year] || null;
|
||||
const current = picks && picks[year];
|
||||
|
||||
$('others-title').hidden = false;
|
||||
$('others-title').textContent = 'Picks of the seasons nearest to it';
|
||||
if (!picks) {
|
||||
$('others').replaceChildren(notice('error', 'seasons/photos.json was not read (see 1), so the picks are not shown.'));
|
||||
} else {
|
||||
const near = Object.keys(picks).sort((a, b) => Math.abs(a - year) - Math.abs(b - year) || a - b).slice(0, 10);
|
||||
$('others').replaceChildren(near.length
|
||||
? grid(near.map((y) => photoCard({ ...picks[y], thumb: thumbOf(picks[y].file) },
|
||||
{ label: `${y}${y === year ? ' (this season, picked now)' : ''}`, picked: y === year })), 'small')
|
||||
: h('p', { class: 'hint' }, 'No season has a pick yet.'));
|
||||
}
|
||||
|
||||
$('cands-title').textContent = `Candidates for ${year}${list ? ` (${list.length})` : ''}`;
|
||||
if (!list) {
|
||||
$('cands').replaceChildren(notice('error', `The candidates file has no entry for ${year}: run tools/commons_candidates.py again.`));
|
||||
return;
|
||||
}
|
||||
if (!list.length) {
|
||||
$('cands').replaceChildren(notice('', `No freely licensed photo in “${year} Formula One season cars” was found; until one is picked, the season poster is drawn without a photo.`));
|
||||
return;
|
||||
}
|
||||
state.chosen = state.chosen && state.chosen.key === year ? state.chosen : null;
|
||||
$('cands').replaceChildren(h('p', { class: 'hint' }, `From Commons’ “${year} Formula One season cars”, the best ${list.length} by quality marks, size and landscape.`),
|
||||
grid(list.map((c) => photoCard(c, {
|
||||
picked: current && current.file === c.file,
|
||||
label: current && current.file === c.file ? 'Picked now' : null,
|
||||
choose: (card) => choose(year, c, card, 'seasons/photos.json', 'seasons'),
|
||||
}))));
|
||||
if (!state.chosen) showEntry();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------ controls
|
||||
|
||||
function seg(id, key) {
|
||||
$(id).addEventListener('click', (e) => {
|
||||
const b = e.target.closest('button');
|
||||
if (!b) return;
|
||||
state[key] = b.dataset.v;
|
||||
render();
|
||||
if (state.chosen) showEntry();
|
||||
});
|
||||
}
|
||||
seg('mode', 'mode');
|
||||
seg('treat', 'treat');
|
||||
seg('frame', 'frame');
|
||||
$('season').addEventListener('change', () => { state.chosen = null; render(); });
|
||||
|
||||
function fillSeasons() {
|
||||
const years = Object.keys(state.candidates.seasons).sort();
|
||||
const want = params.get('season') || '2024';
|
||||
$('season').replaceChildren(...years.map((y) => h('option', { value: y }, `${y} · ${state.candidates.seasons[y].length} candidate${state.candidates.seasons[y].length === 1 ? '' : 's'}`)));
|
||||
$('season').value = years.includes(want) ? want : years[years.length - 1];
|
||||
}
|
||||
|
||||
render();
|
||||
readFile('candidates', () => { fillSeasons(); render(); });
|
||||
readFile('circuits', render);
|
||||
readFile('seasons', render);
|
||||
layoutPicker($('layout-picker'), {
|
||||
treeCard: $('choose'),
|
||||
sync: true,
|
||||
onChange: (p) => { state.pick = p; state.chosen = null; render(); },
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user