add img gen

This commit is contained in:
tree🌴 2024-03-07 13:28:46 +01:00
parent 0a4a0f4616
commit f8a239b8ac
35 changed files with 111 additions and 1 deletions

View File

@ -9,6 +9,9 @@ build:
sync: sync:
deno run --allow-all utils/sync.js deno run --allow-all utils/sync.js
images:
deno run --allow-all utils/images.js
test: test:
deno test --allow-all utils/test.js deno test --allow-all utils/test.js

View File

@ -1,4 +1,12 @@
$defs: $defs:
design:
type: object
additionalProperties: false
required:
- image
properties:
image:
type: string
project: project:
type: object type: object
additionalProperties: false additionalProperties: false
@ -85,6 +93,10 @@ $defs:
type: array type: array
name-extension: name-extension:
type: string type: string
design:
$ref: "#/$defs/design"
images:
type: object
person: person:
type: object type: object
additionalProperties: false additionalProperties: false

Binary file not shown.

After

Width:  |  Height:  |  Size: 330 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 359 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 132 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 164 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 162 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 559 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 535 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 172 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 212 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 209 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 243 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 272 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 94 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 108 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 91 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 695 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 699 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 280 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 314 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 307 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 368 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 341 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 120 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 151 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 158 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 534 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 568 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 174 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 254 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 267 KiB

View File

@ -101,6 +101,8 @@
speakers: speakers:
- odysseas - odysseas
- mykola-siusko - mykola-siusko
design:
image: athens01
# - id: w3pm-lib1 # - id: w3pm-lib1
# type: meetup # type: meetup
@ -153,6 +155,8 @@
speakers: speakers:
- mykola-siusko - mykola-siusko
- gabari - gabari
design:
image: amsterdam01
- id: m24tll - id: m24tll
issue: 10 issue: 10
@ -167,6 +171,8 @@
optional: true optional: true
links: links:
rsvp: https://lu.ma/w3pn-meetup-tallinn1 rsvp: https://lu.ma/w3pn-meetup-tallinn1
design:
image: tallinn01
- id: m24opo - id: m24opo
issue: 21 issue: 21
@ -201,6 +207,8 @@
links: links:
rsvp: https://lu.ma/w3pn-meetup-berlin1 rsvp: https://lu.ma/w3pn-meetup-berlin1
signal: https://signal.group/#CjQKIHv5swzLDOrTd1QqR4L9eb-6XPZERnp3ZEoxBCJeY12fEhAPmoC2dqZzLMRWV7wlAq5A signal: https://signal.group/#CjQKIHv5swzLDOrTd1QqR4L9eb-6XPZERnp3ZEoxBCJeY12fEhAPmoC2dqZzLMRWV7wlAq5A
design:
image: berlin02
- id: s24prg - id: s24prg
issue: 11 issue: 11
@ -223,6 +231,8 @@
- gabari - gabari
- radek-svarz - radek-svarz
- mykola-siusko - mykola-siusko
design:
image: summit02
- id: h24ble - id: h24ble
issue: 7 issue: 7
@ -396,6 +406,8 @@
- mykola-siusko - mykola-siusko
- pg - pg
- tree - tree
design:
image: brno01
- id: c24brn - id: c24brn
issue: 24 issue: 24

View File

@ -34,7 +34,7 @@ export class Engine {
if (await exists(join(dir, "index.yaml"))) { if (await exists(join(dir, "index.yaml"))) {
const out = await readYamlFile(join(dir, "index.yaml")); const out = await readYamlFile(join(dir, "index.yaml"));
if (opts.loader === "events") { if (opts.loader === "events") {
// check speaker connection // check speaker connection & load event images
for (const ev of out) { for (const ev of out) {
if (ev.speakers) { if (ev.speakers) {
for (const spId of ev.speakers) { for (const spId of ev.speakers) {
@ -43,6 +43,21 @@ export class Engine {
} }
} }
} }
// load events images
const year = ev.date.match(/^(\d{4})/)[1];
const yearDir = join(dir, '_images', year);
if (!await exists(yearDir)) {
continue
}
const images = {}
for await (const ie of Deno.readDir(yearDir)) {
const [id, ext] = ie.name.split(".");
if (id.match(new RegExp(`^${ev.id}-`))) {
const imgName = id.split('-').slice(1).join('-')
images[imgName] = `https://data.web3privacy.info/img/events/${year}/${id}.${ext}`;
}
}
ev.images = images
} }
} }
return out; return out;
@ -55,6 +70,7 @@ export class Engine {
images.push({ id, ext }); images.push({ id, ext });
} }
} }
const arr = []; const arr = [];
for await (const dirEntry of Deno.readDir(dir)) { for await (const dirEntry of Deno.readDir(dir)) {
const [fn, ext] = dirEntry.name.split("."); const [fn, ext] = dirEntry.name.split(".");
@ -109,6 +125,12 @@ export class Engine {
join(DEST_DIR, "img", "people"), join(DEST_DIR, "img", "people"),
); );
// copy event images
await copy(
join(SRC_DIR, "events", "_images"),
join(DEST_DIR, "img", "events"),
);
await writeJSONFile( await writeJSONFile(
join(DEST_DIR, "index.json"), join(DEST_DIR, "index.json"),
Object.assign({}, this.rendered), Object.assign({}, this.rendered),

61
utils/images.js Normal file
View File

@ -0,0 +1,61 @@
import { Engine } from "./engine.js";
import { join } from "https://deno.land/std@0.208.0/path/mod.ts";
import { exists } from "https://deno.land/std@0.213.0/fs/exists.ts";
const engine = new Engine();
await engine.init();
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,
format: 'webp',
scale: 4,
})
});
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) {
const destFn = join(DEST_DIR, year, `${event.id}-${format}.webp`);
if (await exists(destFn)) {
console.log(`${destFn} existing, skipping ..`)
continue;
}
await genImage(
destFn,
`https://beta.web3privacy.info/gen/event?id=${event.id}&image=${design.image}`,
`#img-${format}`
);
}
}