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/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 ( - + { - 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); 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]), + sanitizeUrl(Object.values(t)[0]) ); } return parsedYaml; }); -writeFileSync( - './public/projects.json', - 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");