diff --git a/Makefile b/Makefile index d1d922b..2d25f7f 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/utils/images.js b/utils/images.js index bc8355a..311ccbd 100644 --- a/utils/images.js +++ b/utils/images.js @@ -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) { diff --git a/web/public/img/2024-05.png b/web/public/img/2024-05.png new file mode 100644 index 0000000..5588593 Binary files /dev/null and b/web/public/img/2024-05.png differ diff --git a/web/public/img/2024-06.png b/web/public/img/2024-06.png new file mode 100644 index 0000000..c37d10b Binary files /dev/null and b/web/public/img/2024-06.png differ diff --git a/web/public/img/2024-07.png b/web/public/img/2024-07.png new file mode 100644 index 0000000..0cb4a5d Binary files /dev/null and b/web/public/img/2024-07.png differ diff --git a/web/public/img/2024-08.png b/web/public/img/2024-08.png new file mode 100644 index 0000000..ac18bb4 Binary files /dev/null and b/web/public/img/2024-08.png differ diff --git a/web/public/img/2024-09.png b/web/public/img/2024-09.png new file mode 100644 index 0000000..468e554 Binary files /dev/null and b/web/public/img/2024-09.png differ diff --git a/web/public/img/2024-10.png b/web/public/img/2024-10.png new file mode 100644 index 0000000..81da507 Binary files /dev/null and b/web/public/img/2024-10.png differ diff --git a/web/public/img/2024-13.png b/web/public/img/2024-13.png new file mode 100644 index 0000000..9abc3f9 Binary files /dev/null and b/web/public/img/2024-13.png differ diff --git a/web/public/img/2024-14.png b/web/public/img/2024-14.png new file mode 100644 index 0000000..ba95061 Binary files /dev/null and b/web/public/img/2024-14.png differ diff --git a/web/public/img/2024-15.png b/web/public/img/2024-15.png new file mode 100644 index 0000000..0f5e8d0 Binary files /dev/null and b/web/public/img/2024-15.png differ diff --git a/web/public/img/2024-16.png b/web/public/img/2024-16.png new file mode 100644 index 0000000..69f3cf9 Binary files /dev/null and b/web/public/img/2024-16.png differ diff --git a/web/public/img/2024-17.png b/web/public/img/2024-17.png new file mode 100644 index 0000000..d33b697 Binary files /dev/null and b/web/public/img/2024-17.png differ diff --git a/web/public/img/2024-18.png b/web/public/img/2024-18.png new file mode 100644 index 0000000..c5db130 Binary files /dev/null and b/web/public/img/2024-18.png differ diff --git a/web/public/img/cover.png b/web/public/img/cover.png new file mode 100644 index 0000000..4865c87 Binary files /dev/null and b/web/public/img/cover.png differ