Commit 817ecad1 by PLN (Algolia)

hydra-assets: absolute external refs fetched as-is, ///home paths normalized,…

hydra-assets: absolute external refs fetched as-is, ///home paths normalized, >5MB assets downscaled to 1920px JPEG
parent 3a114751
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -26,7 +26,9 @@
"dusty-halley": {
"https://git.plnech.fr/pln/Hydra/raw/master/StarryNights/img/halley.png": "/images/hydra/dusty-halley-halley.png"
},
"fantome": {},
"fantome": {
"https://freesvg.org/img/PutinFace.png": "/images/hydra/fantome-PutinFace.png"
},
"full_moon": {
"https://git.plnech.fr/pln/Hydra/raw/master/biarritz/fullmoon.avif": "/images/hydra/full_moon-fullmoon.jpg"
},
......@@ -38,12 +40,16 @@
"https://git.plnech.fr/pln/Hydra/raw/master/StarryNights/img/august-15-2019-triangulum-galaxy.png": "/images/hydra/karine-august-15-2019-triangulum-galaxy.png",
"https://git.plnech.fr/pln/Hydra/raw/master/StarryNights/img/adenora.png": "/images/hydra/karine-adenora.png"
},
"lucia": {},
"lucia": {
"https://imagine.gsfc.nasa.gov/hst_bday/images/april-21-2019-jupiter.jpg": "/images/hydra/lucia-april-21-2019-jupiter.jpg"
},
"march-4": {
"file:///home/pln/Work/Hydra/StarryNights/img/february-24-2019-saturn-and-moons.jpg": "/images/hydra/march-4-february-24-2019-saturn-and-moons.jpg"
},
"petrole": {},
"pierre_feuilles": {},
"pierre_feuilles": {
"https://images.unsplash.com/photo-1477414348463-c0eb7f1359b6?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2670&q=80": "/images/hydra/pierre_feuilles-photo-1477414348463-c0eb7f1359b6_ixlib_rb-1.2.1_ixid_MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8_auto_format_fit_crop_w_2670_q_80"
},
"planche": {},
"poussiere_dor": {},
"square-worlds": {
......@@ -65,6 +71,44 @@
"https://git.plnech.fr/pln/Hydra/img/tulipes.jpeg": "/images/hydra/tulipes-tulipes.jpeg"
},
"yet": {
"StarryNights/img/Webb_deepest_yet.png": "/images/hydra/yet-Webb_deepest_yet.jpg"
"StarryNights/img/Webb_deepest_yet.png": "/images/hydra/yet-Webb_deepest_yet.jpg",
"https://git.plnech.fr/pln/Hydra/raw/master/StarryNights/img/Webb_deepest_yet.png": "/images/hydra/yet-Webb_deepest_yet.jpg"
},
"30wild": {
"https://imagine.gsfc.nasa.gov/hst_bday/images/march-30-2019-four-faces-of-mars.jpg": "/images/hydra/30wild-march-30-2019-four-faces-of-mars.jpg"
},
"aurores": {
"///home/pln/Work/Hydra/img/aurores.jpeg": "/images/hydra/aurores-aurores.jpeg"
},
"douce-nebuleuse": {
"https://git.plnech.fr/pln/Hydra/raw/d36c64fc40b803849a26fc63c1a3191b12eb9955/StarryNights/img/july1.jpeg": "/images/hydra/douce-nebuleuse-july1.jpeg",
"https://imagine.gsfc.nasa.gov/hst_bday/images/july-1-2019-comet-shoemaker-levy-9-fragments.jpg": "/images/hydra/douce-nebuleuse-july-1-2019-comet-shoemaker-levy-9-fragments.jpg"
},
"dual-ring": {
"file:///home/pln/Work/Hydra/StarryNights/img/Webb_deepest_yet.png": "/images/hydra/dual-ring-Webb_deepest_yet.jpg"
},
"edge": {
"/home/pln/Work/Hydra/StarryNights/img/Edge.png": "/images/hydra/edge-Edge.jpg"
},
"eglantine22": {
"/home/pln/Work/Hydra/StarryNights/img/july-6-2019-planetary-nebula-ngc-5189.jpg": "/images/hydra/eglantine22-july-6-2019-planetary-nebula-ngc-5189.jpg"
},
"hollow-sun": {
"/home/pln/Work/Hydra/StarryNights/img/brano-tLFHQIqALz0-unsplash.jpg": "/images/hydra/hollow-sun-brano-tLFHQIqALz0-unsplash.jpg"
},
"moire-purple": {
"/home/pln/Work/Hydra/StarryNights/img/arp299.jpg": "/images/hydra/moire-purple-arp299.jpg"
},
"olivia53": {
"/home/pln/Work/Hydra/StarryNights/img/july-5-2019-trifid-nebula.jpg": "/images/hydra/olivia53-july-5-2019-trifid-nebula.jpg"
},
"september-galaxy": {
"file:///home/pln/Work/Hydra/StarryNights/img/september-28-2019-galaxy-ngc-300.jpg": "/images/hydra/september-galaxy-september-28-2019-galaxy-ngc-300.jpg",
"https://git.plnech.fr/pln/Hydra/raw/eecd6aaf74b4af18af9af22a4eed8d6b201d4824/StarryNights/img/september-28-2019-galaxy-ngc-300.jpg": "/images/hydra/september-galaxy-september-28-2019-galaxy-ngc-300.jpg",
"file:///home/pln/Work/Hydra/StarryNights/img/cosmos.jpg": "/images/hydra/september-galaxy-cosmos.jpg",
"https://git.plnech.fr/pln/Hydra/raw/eecd6aaf74b4af18af9af22a4eed8d6b201d4824/StarryNights/img/cosmos.jpg": "/images/hydra/september-galaxy-cosmos.jpg"
},
"shoe": {
"file:///home/pln/Work/Hydra/StarryNights/img/ShoemakerLevy9.png": "/images/hydra/shoe-ShoemakerLevy9.png"
}
}
......@@ -18,6 +18,7 @@
import fs from 'node:fs';
import path from 'node:path';
import { execFileSync } from 'node:child_process';
import matter from 'gray-matter';
const HYDRAS = path.resolve(process.cwd(), 'content/hydras');
......@@ -44,8 +45,19 @@ async function download(url, dest) {
const res = await fetch(url);
if (!res.ok) throw new Error(`HTTP ${res.status} for ${url}`);
const buf = Buffer.from(await res.arrayBuffer());
if (buf.length > 8 * 1024 * 1024) throw new Error(`asset too big: ${url}`);
if (buf.length > 30 * 1024 * 1024) throw new Error(`asset too big: ${url}`);
// heavy originals get the NASA-set treatment: 1920px JPEG keeps the 404
// gallery light (Webb's deepest field is 28MB as PNG)
if (buf.length > 5 * 1024 * 1024) {
const tmp = dest + '.tmp';
fs.writeFileSync(tmp, buf);
const jpg = dest.replace(/\.\w+$/, '.jpg');
execFileSync('sips', ['-Z', '1920', '-s', 'format', 'jpeg', '-s', 'formatOptions', '80', tmp, '--out', jpg], { stdio: 'pipe' });
fs.rmSync(tmp);
return jpg;
}
fs.writeFileSync(dest, buf);
return dest;
}
for (const { id, url } of sketchUrls) {
......@@ -61,19 +73,31 @@ for (const { id, url } of sketchUrls) {
manifest[id] ??= {};
for (const [, , , ref] of code.matchAll(/(initImage\()\s*(["'])(.*?)\2/g)) {
if (manifest[id][ref]) continue;
// normalize: file:// work paths, absolute work paths, and git URLs
// (raw and plain) all map to a repo-relative path
const rel = ref
.replace(/^file:\/\/\/home\/pln\/Work\/Hydra\//, '')
.replace(/^\/home\/pln\/Work\/Hydra\//, '')
.replace(/^https?:\/\/[^/]+\/pln\/Hydra(?:\/raw\/[^/]+)?\//, '');
// normalize: file:// work paths, absolute work paths (1–3 slashes), and
// git URLs (raw and plain) all map to a repo-relative path; any other
// absolute http ref is fetched as-is
const hydraRepo = /^https?:\/\/[^/]+\/pln\/Hydra(?:\/raw\/[^/]+)?\//;
const external = /^https?:\/\//.test(ref) && !hydraRepo.test(ref);
const rel = external
? ref
: ref
.replace(/^file:\/\//, '')
.replace(/^\/+home\/pln\/Work\/Hydra\//, '')
.replace(hydraRepo, '');
const destName = `${id}-${path.basename(rel).replace(/[^\w.-]/g, '_')}`;
const dest = path.join(OUT, destName);
const local = `/images/hydra/${destName}`;
try {
if (!fs.existsSync(dest)) {
await download(RAW + rel, dest);
const saved = await download(external ? ref : RAW + rel, dest);
fetched += 1;
if (saved !== dest) {
// downscaled: the manifest points at the JPEG twin
const localJpg = `/images/hydra/${path.basename(saved)}`;
manifest[id][ref] = localJpg;
console.log(`${id}: ${rel} → ${localJpg} (downscaled)`);
continue;
}
}
manifest[id][ref] = local;
console.log(`${id}: ${rel} → ${local}`);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment