mirror of
https://github.com/web3privacy/news.git
synced 2024-10-15 18:06:26 +02:00
separate image gen util
This commit is contained in:
parent
68367e26b6
commit
28435f2463
4 changed files with 51 additions and 37 deletions
2
.github/workflows/deploy.yml
vendored
2
.github/workflows/deploy.yml
vendored
|
@ -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
|
||||
|
|
5
Makefile
5
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
|
|
@ -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();
|
||||
|
|
46
utils/images.js
Normal file
46
utils/images.js
Normal file
|
@ -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}`);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue