explorer-data/utils/gen.js

62 lines
1.4 KiB
JavaScript
Raw Normal View History

2023-10-07 20:48:35 +02:00
import yaml from "npm:js-yaml";
2023-10-07 20:01:09 +02:00
function slugify(input) {
2023-10-07 20:48:35 +02:00
if (!input) {
return "";
}
2023-10-07 20:01:09 +02:00
2023-10-07 20:48:35 +02:00
// make lower case and trim
var slug = input.toLowerCase().trim();
2023-10-07 20:01:09 +02:00
2023-10-07 20:48:35 +02:00
// remove accents from charaters
slug = slug.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
2023-10-07 20:01:09 +02:00
2023-10-07 20:48:35 +02:00
// replace invalid chars with spaces
slug = slug.replace(/[^a-z0-9\s-]/g, " ").trim();
2023-10-07 20:01:09 +02:00
2023-10-07 20:48:35 +02:00
// replace multiple spaces or hyphens with a single hyphen
slug = slug.replace(/[\s-]+/g, "-");
2023-10-07 20:01:09 +02:00
2023-10-07 20:48:35 +02:00
return slug;
2023-10-07 20:01:09 +02:00
}
2023-10-07 20:48:35 +02:00
const projectDir = "src/projects";
async function genCat(cat) {
const catDir = `${projectDir}/${cat}`;
const f = await Deno.readTextFile(`${catDir}/src.json`);
const src = JSON.parse(f);
for (const p of src.data.Projects) {
const id = slugify(p.Project);
const pDir = `${catDir}/${id}`;
console.log(`${id}:\n -> ${pDir}`);
try {
await Deno.mkdir(pDir);
} catch {}
const out = {
name: p.Project,
2023-10-07 21:27:58 +02:00
categories: [cat],
2023-10-07 20:48:35 +02:00
description: p.Description,
ecosystem: p.Ecosystem,
2023-10-07 21:39:00 +02:00
product_readiness: p.ProductReadiness,
2023-10-07 20:48:35 +02:00
links: {
2023-10-07 21:36:20 +02:00
github: p.GitHub && p.GitHub !== '-' ? p.GitHub : undefined,
2023-10-07 20:48:35 +02:00
},
team: {
2023-10-07 21:36:20 +02:00
anonymous: p.Team !== "Public"
2023-10-07 20:48:35 +02:00
},
};
2023-10-07 21:36:20 +02:00
if (p.TeamLink && p.TeamLink !== '') {
out.team.company = { link: p.TeamLink }
}
2023-10-07 20:48:35 +02:00
const yml = yaml.dump(out);
await Deno.writeTextFile(`${pDir}/index.yaml`, yml);
//console.log(id, yml)
}
2023-10-07 20:01:09 +02:00
}
2023-10-07 20:48:35 +02:00
genCat(Deno.args[0]);