2024-03-07 13:28:46 +01:00
|
|
|
import { Engine } from "./engine.js";
|
2024-09-08 23:04:20 +02:00
|
|
|
import { join } from "jsr:@std/path@0.224.0";
|
|
|
|
import { exists } from "jsr:@std/fs@0.224.0";
|
2024-03-07 13:28:46 +01:00
|
|
|
|
|
|
|
const engine = new Engine();
|
|
|
|
await engine.init();
|
|
|
|
|
2024-03-07 15:32:10 +01:00
|
|
|
const FORMAT = 'png';
|
2024-03-07 13:46:31 +01:00
|
|
|
|
2024-03-07 13:28:46 +01:00
|
|
|
async function genImage (destFn, url, element) {
|
|
|
|
|
|
|
|
console.log(`Getting ${url} (${element}) (dest=${destFn})`)
|
|
|
|
const file = await fetch("https://html2svg.gwei.cz", {
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
},
|
|
|
|
body: JSON.stringify({
|
|
|
|
url,
|
|
|
|
element,
|
2024-03-07 13:46:31 +01:00
|
|
|
format: FORMAT,
|
2024-03-07 13:28:46 +01:00
|
|
|
scale: 4,
|
2024-03-07 15:32:10 +01:00
|
|
|
//quality: 100,
|
2024-03-07 13:28:46 +01:00
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
if (file.body) {
|
|
|
|
const fileOutput = await Deno.open(destFn, { write: true, create: true });
|
|
|
|
await file.body.pipeTo(fileOutput.writable);
|
|
|
|
console.log(`File written: ${destFn}`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// events
|
|
|
|
const DEST_DIR = './src/events/_images';
|
|
|
|
const eventFormats = [
|
|
|
|
'square',
|
|
|
|
'wide-square',
|
|
|
|
'wide',
|
|
|
|
'poster',
|
|
|
|
'poster-simple'
|
|
|
|
]
|
|
|
|
|
|
|
|
for(const event of engine.rendered.events) {
|
|
|
|
if (!event.design) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
const year = event.date.match(/^(\d{4})/)[1]
|
|
|
|
const design = event.design
|
|
|
|
for (const format of eventFormats) {
|
|
|
|
|
2024-03-07 13:46:31 +01:00
|
|
|
const destFn = join(DEST_DIR, year, `${event.id}-${format}.${FORMAT}`);
|
2024-03-07 13:28:46 +01:00
|
|
|
if (await exists(destFn)) {
|
|
|
|
console.log(`${destFn} existing, skipping ..`)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
await genImage(
|
|
|
|
destFn,
|
2024-03-16 19:56:17 +01:00
|
|
|
`https://web3privacy.info/gen/event?id=${event.id}&img=${design.image}`,
|
2024-03-07 13:28:46 +01:00
|
|
|
`#img-${format}`
|
|
|
|
);
|
|
|
|
}
|
2024-08-31 03:46:27 +02:00
|
|
|
}
|