diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index a9b6626..36059aa 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -29,7 +29,7 @@ jobs: deno-version: v1.x - name: Build bundle - run: make build + run: make build images - name: Setup node uses: actions/setup-node@v4 diff --git a/Makefile b/Makefile index 7a3d0d0..ba78cd2 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,9 @@ all: build frontend compile build: deno run --allow-all utils/build.js +images: + deno run --allow-all utils/images.js + frontend: cd web && npm install && npm run build @@ -10,7 +13,7 @@ readme: deno run --allow-all utils/readme.js sync: - make readme + make build readme compile: cp -r web/dist/** dist \ No newline at end of file diff --git a/utils/build.js b/utils/build.js index ae1bf94..c598355 100644 --- a/utils/build.js +++ b/utils/build.js @@ -38,24 +38,6 @@ async function build() { } await emptyDir(DEST_DIR); - const imgDir = join(DEST_DIR, "img"); - await emptyDir(imgDir); - - // get images - for (const issue of issues) { - await genImage( - `https://news.web3privacy.info/image/${issue.week}?${ - new Date().valueOf() - }`, - join(imgDir, `${issue.week}.png`), - ); - } - - // make cover - await genImage( - `https://news.web3privacy.info/cover`, - join(imgDir, "cover.png"), - ); const outputFn = join(DEST_DIR, "index.json"); await writeJSONFile(outputFn, issues); @@ -95,21 +77,4 @@ async function writeJSONFile(fn, data) { return Deno.writeTextFile(fn, JSON.stringify(data, null, 2)); } -async function genImage(url, fn) { - const imgResp = await fetch("https://html2svg.gwei.cz", { - method: "POST", - body: JSON.stringify({ - url, - format: "png", - width: 1920, - height: 960, - }), - }); - - if (imgResp.body) { - const file = await Deno.open(fn, { write: true, create: true }); - await imgResp.body.pipeTo(file.writable); - } -} - build(); diff --git a/utils/images.js b/utils/images.js new file mode 100644 index 0000000..bc8355a --- /dev/null +++ b/utils/images.js @@ -0,0 +1,46 @@ +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"; + +const DEST_DIR = "./dist"; + +const imgDir = join(DEST_DIR, "img"); +await emptyDir(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`), + ); +} + +// make cover +await genImage( + `https://news.web3privacy.info/cover`, + join(imgDir, "cover.png"), +); + +console.log("Done"); + +async function genImage(url, fn) { + const imgResp = await fetch("https://html2svg.gwei.cz", { + method: "POST", + body: JSON.stringify({ + url, + format: "png", + width: 1920, + height: 960, + }), + }); + + if (imgResp.body) { + const file = await Deno.open(fn, { write: true, create: true }); + await imgResp.body.pipeTo(file.writable); + + console.log(`Image written: ${fn}`); + } +}