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:
+11
-5
@@ -182,7 +182,7 @@
|
||||
return null;
|
||||
}
|
||||
setStatus(statusEl, 'ok', summary);
|
||||
return { status: res.status, type, blob, ms, size: blob.size, url };
|
||||
return { status: res.status, type, blob, ms, size: blob.size, url, headers: res.headers };
|
||||
}
|
||||
|
||||
/** Fetches JSON for a card and shows it in its `.result`; returns the parsed value or null. */
|
||||
@@ -243,10 +243,13 @@
|
||||
return pre;
|
||||
}
|
||||
|
||||
/** What the first bytes of a body are: 'png', 'svg', 'json' or 'unknown'. */
|
||||
/** What the first bytes of a body are: 'png', 'jpg', 'webp', 'svg', 'json' or 'unknown'. */
|
||||
async function sniff(blob) {
|
||||
const head = new Uint8Array(await blob.slice(0, 256).arrayBuffer());
|
||||
if (head[0] === 0x89 && head[1] === 0x50 && head[2] === 0x4e && head[3] === 0x47) return 'png';
|
||||
if (head[0] === 0xff && head[1] === 0xd8 && head[2] === 0xff) return 'jpg';
|
||||
const ascii = (from, to) => String.fromCharCode(...head.slice(from, to));
|
||||
if (ascii(0, 4) === 'RIFF' && ascii(8, 12) === 'WEBP') return 'webp';
|
||||
const text = new TextDecoder().decode(head).trimStart();
|
||||
if (text.startsWith('<?xml') || text.startsWith('<svg')) return 'svg';
|
||||
if (text.startsWith('{') || text.startsWith('[')) return 'json';
|
||||
@@ -261,9 +264,11 @@
|
||||
return el._objectURL;
|
||||
}
|
||||
|
||||
const RASTER = { png: 'image/png', jpg: 'image/jpeg', webp: 'image/webp' };
|
||||
|
||||
/**
|
||||
* Shows an image answer. `expected` is 'png' or 'svg'; when the body is something else, says so first
|
||||
* (loudly) and shows what came back.
|
||||
* Shows an image answer. `expected` is 'png', 'jpg', 'webp' or 'svg'; when the body is something else,
|
||||
* says so first (loudly) and shows what came back.
|
||||
*/
|
||||
async function showImage(el, answer, expected, opts = {}) {
|
||||
const got = await sniff(answer.blob);
|
||||
@@ -273,7 +278,8 @@
|
||||
if (opts.status) setStatus(opts.status, 'error', `${opts.status.textContent} — not ${expected.toUpperCase()}`);
|
||||
parts.push(notice('error', `Asked for ${expected.toUpperCase()}, but the body is ${got === 'unknown' ? 'not an image this page knows' : `${got === 'svg' ? 'an' : 'a'} ${got.toUpperCase()} document`} (the Content-Type header says ${answer.type}).`));
|
||||
if (got === 'svg') blob = new Blob([blob], { type: 'image/svg+xml' });
|
||||
else if (got !== 'png') { el.replaceChildren(...parts); return false; }
|
||||
else if (RASTER[got]) blob = new Blob([blob], { type: RASTER[got] });
|
||||
else { el.replaceChildren(...parts); return false; }
|
||||
if (got === 'svg') parts.push(h('p', {}, 'What came back, shown as an SVG:'));
|
||||
} else if (expected === 'svg') {
|
||||
blob = new Blob([blob], { type: 'image/svg+xml' });
|
||||
|
||||
Reference in New Issue
Block a user