fix img gen

This commit is contained in:
tree🌴 2024-05-07 01:05:47 +02:00
parent 6c79cd634d
commit ec25d79ab3
15 changed files with 26 additions and 17 deletions

View File

@ -4,7 +4,7 @@ build:
deno run --allow-all utils/build.js
images:
# deno run --allow-all utils/images.js
deno run --allow-all utils/images.js
frontend:
cd web && npm install && npm run build

View File

@ -1,31 +1,37 @@
import { join } from "https://deno.land/std@0.208.0/path/mod.ts";
import { emptyDir } from "https://deno.land/std@0.196.0/fs/empty_dir.ts";
import { ensureDir } from "https://deno.land/std@0.224.0/fs/ensure_dir.ts";
import { existsSync } from "https://deno.land/std@0.224.0/fs/exists.ts";
const DEST_DIR = "./dist";
const DATA_DIR = "./data";
const imgDir = join(DEST_DIR, "img");
await emptyDir(imgDir);
const imgDir = "./web/public/img";
await ensureDir(imgDir);
const issues = JSON.parse(
await Deno.readTextFile(join(DEST_DIR, "index.json")),
);
// get images
for (const issue of issues) {
await genImage(
`https://news.web3privacy.info/image/${issue.week}?${new Date().valueOf()}`,
join(imgDir, `${issue.week}.png`),
);
for (const { name: year } of Deno.readDirSync(DATA_DIR)) {
for (const { name: fn } of Deno.readDirSync(join(DATA_DIR, year))) {
const week = fn.match(/^week(\d+)/)?.[1];
if (!week) continue;
const yearWeek = `${year}-${week}`;
const imgn = `https://news.web3privacy.info/image/${yearWeek}?${new Date().valueOf()}`;
const outputFn = join(imgDir, `${yearWeek}.png`);
if (existsSync(outputFn)) continue;
console.log('Processing:', imgn);
await genImage(imgn, outputFn);
}
}
// make cover
await genImage(
`https://news.web3privacy.info/cover`,
join(imgDir, "cover.png"),
);
const coverFn = join(imgDir, "cover.png");
if (!existsSync(coverFn)) {
await genImage(`https://news.web3privacy.info/cover`, coverFn);
}
console.log("Done");
// ---------
async function genImage(url, fn) {
const imgResp = await fetch("https://html2svg.gwei.cz", {
method: "POST",
@ -35,6 +41,9 @@ async function genImage(url, fn) {
width: 1920,
height: 960,
}),
headers: {
"content-type": "application/json",
}
});
if (imgResp.body) {

BIN
web/public/img/2024-05.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

BIN
web/public/img/2024-06.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

BIN
web/public/img/2024-07.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

BIN
web/public/img/2024-08.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

BIN
web/public/img/2024-09.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

BIN
web/public/img/2024-10.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

BIN
web/public/img/2024-13.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

BIN
web/public/img/2024-14.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

BIN
web/public/img/2024-15.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

BIN
web/public/img/2024-16.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

BIN
web/public/img/2024-17.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

BIN
web/public/img/2024-18.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

BIN
web/public/img/cover.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB