This commit is contained in:
tree🌴 2023-10-08 04:04:22 +02:00
parent da7bff71d4
commit 8eead8afcc
4 changed files with 66 additions and 3 deletions

View File

@ -289,3 +289,15 @@ properties:
type: boolean type: boolean
mainnet: mainnet:
type: boolean type: boolean
logos:
type: array
items:
type: object
properties:
file:
type: string
ext:
type: string
url:
type: string
format: uri

View File

@ -1,4 +1,6 @@
import { emptyDir } from "https://deno.land/std@0.203.0/fs/empty_dir.ts"; import { emptyDir } from "https://deno.land/std@0.203.0/fs/empty_dir.ts";
import { ensureDir } from "https://deno.land/std@0.203.0/fs/ensure_dir.ts";
import { W3PData } from "./w3pdata.js"; import { W3PData } from "./w3pdata.js";
const w3pd = new W3PData(); const w3pd = new W3PData();
@ -10,6 +12,37 @@ try {
await emptyDir(outputDir); await emptyDir(outputDir);
} catch {} } catch {}
for (const p of w3pd.data.projects) {
if (!p.logos) {
continue
}
for (const asset of p.logos) {
const src = `${p._path}/${asset.file}`
const destDir = `${outputDir}/assets/projects/${p.id}`
const dest = `${destDir}/${asset.file}`
await ensureDir(destDir)
await Deno.copyFile(src, dest);
console.log(`${src} -> ${dest}`)
}
}
const bundleFn = `${outputDir}/index.json`; const bundleFn = `${outputDir}/index.json`;
const out = {}
for (const key of Object.keys(w3pd.data)) {
const arr = []
if (key === 'projects') {
for (const p of w3pd.data[key]) {
delete p._path
arr.push(p)
}
}
out[key] = arr
}
await Deno.writeTextFile(bundleFn, JSON.stringify(w3pd.data, null, 2)); await Deno.writeTextFile(bundleFn, JSON.stringify(w3pd.data, null, 2));
console.log(`Bundle writed: ${bundleFn}`); console.log(`Bundle writed: ${bundleFn}`);

View File

@ -34,6 +34,7 @@ for (const col of Object.keys(w3pd.data)) {
const ids = [] const ids = []
for (const item of w3pd.data[col]) { for (const item of w3pd.data[col]) {
delete item._path
const testName = `${col}/${item.id} ` + (col === 'projects' ? `[${item.categories?.join(', ')}]` : '') const testName = `${col}/${item.id} ` + (col === 'projects' ? `[${item.categories?.join(', ')}]` : '')
if (ids.includes(item.id)) { if (ids.includes(item.id)) {

View File

@ -1,5 +1,7 @@
import yaml from "npm:js-yaml"; import yaml from "npm:js-yaml";
const DATA_URL = 'https://data.web3privacy.info'
export class W3PData { export class W3PData {
constructor() { constructor() {
} }
@ -28,10 +30,25 @@ export class W3PData {
const pDir = `${catDir}/${pd.name}`; const pDir = `${catDir}/${pd.name}`;
const indexFn = `${pDir}/index.yaml`; const indexFn = `${pDir}/index.yaml`;
const index = yaml.load( const index = Object.assign({ id: pd.name }, yaml.load(
await Deno.readTextFile(indexFn), await Deno.readTextFile(indexFn),
); ))
out.projects.push(Object.assign({ id: pd.name }, index));
index._path = pDir
// read attachments
const logos = []
for await (const pa of Deno.readDir(pDir)) {
const pam = pa.name.match(/^(logo)\.(.+)$/)
if (pam && pam[1] === 'logo') {
logos.push({ file: pam[0], ext: pam[2], url: `${DATA_URL}/assets/projects/${index.id}/${pam[0]}` })
}
}
if (logos.length > 0) {
index.logos = logos
}
out.projects.push(index);
} }
} }
} }