diff --git a/scripts/cars-import.ts b/scripts/cars-import.ts index 45e9911..c41fb02 100644 --- a/scripts/cars-import.ts +++ b/scripts/cars-import.ts @@ -391,12 +391,16 @@ function cleanTradeName(raw: string, make: string): string { else if (s.startsWith(`${make} `) && s.length > make.length + 1) s = s.slice(make.length + 1); else break; } + // Make glued to a number ("MAZDA2 HYBRID" -> "2 HYBRID", "JAECOO7" -> "7"). + const mk0 = make.replace(/[^A-Z]/g, ''); + const glued = s.match(new RegExp(`^${mk0}(\\d+)\\b(.*)$`)); + if (mk0.length >= 3 && glued) s = `${glued[1]}${glued[2]}`; // Misspelt make as first word ("PEUGOT 205" under PEUGEOT). const [w0, ...restW] = s.split(' '); - const mk0 = make.replace(/[^A-Z]/g, ''); if ( restW.length && mk0.length >= 5 && + /^[A-Z]+$/.test(w0) && // "MAZDA2 HYBRID" and "JAECOO7 PHEV" are names, not typos w0 !== mk0 && w0.slice(0, 4) === mk0.slice(0, 4) && Math.abs(w0.length - mk0.length) <= 1 diff --git a/scripts/cars-photos.ts b/scripts/cars-photos.ts index 4e971b0..a290f87 100644 --- a/scripts/cars-photos.ts +++ b/scripts/cars-photos.ts @@ -405,7 +405,10 @@ function toPhoto( file, kind, caption, - thumb: info.thumburl, + // Canonical host, no tracking query: https://upload.wikimedia.org/.../960px- + thumb: info.thumburl + .replace(/\?.*$/, '') + .replace('//thumb.wikimedia.org/', '//upload.wikimedia.org/'), width: info.width, height: info.height, author, diff --git a/src/lib/cars/Gallery.svelte b/src/lib/cars/Gallery.svelte index ab5ab64..9097eb3 100644 --- a/src/lib/cars/Gallery.svelte +++ b/src/lib/cars/Gallery.svelte @@ -14,8 +14,11 @@ let index = $state(0); const current = $derived(photos[index]); const large = (p: CarPhoto) => thumbAt(p.thumb, p.width > 1280 ? 1280 : 960); + const norm = (s: string) => s.toLowerCase().replace(/[^a-z0-9]/g, ''); + // Generation captions that just repeat the model name add nothing. + const caption = (p: CarPhoto) => (p.caption && norm(p.caption) !== norm(name) ? p.caption : null); const alt = (p: CarPhoto, i: number) => - `${p.caption ?? name}, photo ${i + 1} of ${photos.length}`; + `${caption(p) ?? name}, photo ${i + 1} of ${photos.length}`; // Links go to the Commons file page; with JS they open the lightbox instead. function open(event: MouseEvent, i: number) { @@ -47,7 +50,7 @@ -
- - {photos.length} photo{photos.length === 1 ? '' : 's'} from Wikimedia Commons{#if wikipedia} - · Wikipedia{/if} · credits - -
    - {#each photos as p, i (p.file)} -
  1. {i + 1}. {p.caption ?? p.file.replace(/\.\w+$/, '')}: {@render credit(p)}
  2. - {/each} -
-
+
+
+ + {photos.length} photo{photos.length === 1 ? '' : 's'} from Wikimedia Commons · credits & licences + +
    + {#each photos as p, i (p.file)} +
  1. {i + 1}. {caption(p) ?? p.file.replace(/\.\w+$/, '')}: {@render credit(p)}
  2. + {/each} +
+
+ {#if wikipedia} + Read about it on Wikipedia ↗ + {/if} +
@@ -89,8 +98,8 @@ {/key}
{index + 1}/{photos.length}{#if current.caption} - · {current.caption}{/if}{index + 1}/{photos.length}{#if caption(current)} + · {caption(current)}{/if} {@render credit(current)}
@@ -178,6 +187,19 @@ font-size: 0.75rem; color: var(--site-muted); } + .below { + display: flex; + align-items: flex-start; + justify-content: space-between; + gap: 1rem; + } + .wiki { + margin-top: 0.5rem; + flex: none; + font-size: 0.75rem; + color: var(--site-muted); + text-decoration: underline; + } .credits summary { cursor: pointer; }