From 8eead8afcc70df10888b12a5fed8be8a66c83738 Mon Sep 17 00:00:00 2001 From: tree Date: Sun, 8 Oct 2023 04:04:22 +0200 Subject: [PATCH] logos --- schema/project.yaml | 12 ++++++++++++ utils/build.js | 33 +++++++++++++++++++++++++++++++++ utils/test.js | 1 + utils/w3pdata.js | 23 ++++++++++++++++++++--- 4 files changed, 66 insertions(+), 3 deletions(-) diff --git a/schema/project.yaml b/schema/project.yaml index a557d84d..5ac55b71 100644 --- a/schema/project.yaml +++ b/schema/project.yaml @@ -289,3 +289,15 @@ properties: type: boolean mainnet: type: boolean + logos: + type: array + items: + type: object + properties: + file: + type: string + ext: + type: string + url: + type: string + format: uri diff --git a/utils/build.js b/utils/build.js index 58544b1f..d68723dc 100644 --- a/utils/build.js +++ b/utils/build.js @@ -1,4 +1,6 @@ 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"; const w3pd = new W3PData(); @@ -10,6 +12,37 @@ try { await emptyDir(outputDir); } 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 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)); console.log(`Bundle writed: ${bundleFn}`); diff --git a/utils/test.js b/utils/test.js index a95b27db..e5022fcb 100644 --- a/utils/test.js +++ b/utils/test.js @@ -34,6 +34,7 @@ for (const col of Object.keys(w3pd.data)) { const ids = [] for (const item of w3pd.data[col]) { + delete item._path const testName = `${col}/${item.id} ` + (col === 'projects' ? `[${item.categories?.join(', ')}]` : '') if (ids.includes(item.id)) { diff --git a/utils/w3pdata.js b/utils/w3pdata.js index 34e18596..6a8ca87c 100644 --- a/utils/w3pdata.js +++ b/utils/w3pdata.js @@ -1,5 +1,7 @@ import yaml from "npm:js-yaml"; +const DATA_URL = 'https://data.web3privacy.info' + export class W3PData { constructor() { } @@ -28,10 +30,25 @@ export class W3PData { const pDir = `${catDir}/${pd.name}`; const indexFn = `${pDir}/index.yaml`; - const index = yaml.load( + const index = Object.assign({ id: pd.name }, yaml.load( 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); } } }