From faed7ed731a7c21692b09b0da273fe9447900463 Mon Sep 17 00:00:00 2001 From: Kaja Date: Wed, 4 Jun 2025 23:31:02 +0100 Subject: [PATCH 1/2] Generate projects.json in /dist --- .gitignore | 2 ++ src/generate-projects-json.mjs | 38 ++++++++++++++++++---------------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index a547bf36..801501c5 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,5 @@ dist-ssr *.njsproj *.sln *.sw? + +/public/projects.json diff --git a/src/generate-projects-json.mjs b/src/generate-projects-json.mjs index 7f4c23b0..4585ba35 100644 --- a/src/generate-projects-json.mjs +++ b/src/generate-projects-json.mjs @@ -1,25 +1,26 @@ -import { readFileSync, writeFileSync } from 'fs'; -import { globSync } from 'glob'; -import { load } from 'js-yaml'; -import { getCorrectLanguageName } from './languageUtils.mjs'; -import { sanitizeUrl } from './sanitizeUrl.mjs'; +import { readFileSync, writeFileSync } from "fs"; +import { globSync } from "glob"; +import { load } from "js-yaml"; +import { getCorrectLanguageName } from "./languageUtils.mjs"; +import { sanitizeUrl } from "./sanitizeUrl.mjs"; +import { mkdirSync } from "fs"; -const yamls = globSync('./projects/*/*.yaml').sort(); +const yamls = globSync("./projects/*/*.yaml").sort(); const allScreenshots = globSync( - './projects/*/screenshots/*.{png,jpg,jpeg}', + "./projects/*/screenshots/*.{png,jpg,jpeg}" ).sort(); /** @type {import('./types').Project[]} */ const projects = yamls.map((path) => { - const yaml = readFileSync(path, 'utf8'); + const yaml = readFileSync(path, "utf8"); const parsedYaml = /** @type {import('./types').Project} */ (load(yaml)); - const screenshotsPath = path.replace(/\/[^/]*?\.yaml$/, '/screenshots'); + const screenshotsPath = path.replace(/\/[^/]*?\.yaml$/, "/screenshots"); parsedYaml.screenshots = allScreenshots .filter((screenshotPath) => screenshotPath.startsWith(screenshotsPath)) - .map((screenshotPath) => '/' + screenshotPath); + .map((screenshotPath) => "/" + screenshotPath); parsedYaml.languages = parsedYaml.languages.map(getCorrectLanguageName); - parsedYaml.license = parsedYaml.license || 'Unspecified'; - const folderName = path.split('/').slice(-2, -1)[0]; + parsedYaml.license = parsedYaml.license || "Unspecified"; + const folderName = path.split("/").slice(-2, -1)[0]; parsedYaml.slug = folderName; parsedYaml.codeUrl = sanitizeUrl(parsedYaml.codeUrl); @@ -33,15 +34,16 @@ const projects = yamls.map((path) => { } if (parsedYaml.tutorials) { parsedYaml.tutorials = parsedYaml.tutorials.filter((t) => - sanitizeUrl(Object.values(t)[0]), + sanitizeUrl(Object.values(t)[0]) ); } return parsedYaml; }); -writeFileSync( - './public/projects.json', - JSON.stringify(projects, null, 4), - 'utf8', -); +mkdirSync("./dist", { recursive: true }); +const outputPaths = ["./public/projects.json", "./dist/projects.json"]; + +for (const path of outputPaths) { + writeFileSync(path, JSON.stringify(projects, null, 4), "utf8"); +} From 2c7d7b2f67630153f4c4b478dd771a8c81c196a9 Mon Sep 17 00:00:00 2001 From: Kaja Date: Wed, 4 Jun 2025 23:34:26 +0100 Subject: [PATCH 2/2] Fix card styling grid error --- src/components/ProjectListItem.tsx | 4 ++-- src/generate-projects-json.mjs | 19 ++++++++++++------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/components/ProjectListItem.tsx b/src/components/ProjectListItem.tsx index a8c19626..20d77ca2 100644 --- a/src/components/ProjectListItem.tsx +++ b/src/components/ProjectListItem.tsx @@ -43,9 +43,9 @@ const ProjectListItem: React.FC = ({ const isMobileScreen = useMediaQuery(theme.breakpoints.down('sm')); return ( - + { parsedYaml.demoUrl = parsedYaml.demoUrl ? sanitizeUrl(parsedYaml.demoUrl) : null; + if (parsedYaml.authors) { parsedYaml.authors = parsedYaml.authors.map((t) => ({ [Object.keys(t)[0]]: sanitizeUrl(Object.values(t)[0]), })); } + if (parsedYaml.tutorials) { parsedYaml.tutorials = parsedYaml.tutorials.filter((t) => sanitizeUrl(Object.values(t)[0]) @@ -41,9 +45,10 @@ const projects = yamls.map((path) => { return parsedYaml; }); -mkdirSync("./dist", { recursive: true }); -const outputPaths = ["./public/projects.json", "./dist/projects.json"]; - -for (const path of outputPaths) { - writeFileSync(path, JSON.stringify(projects, null, 4), "utf8"); +const outputPath = process.argv[2] || "./dist/projects.json"; +const outputDir = outputPath.split("/").slice(0, -1).join("/"); +if (outputDir) { + mkdirSync(outputDir, { recursive: true }); } + +writeFileSync(outputPath, JSON.stringify(projects, null, 4), "utf8");