diff --git a/src/siteGen/index.js b/src/siteGen/index.js index 6971f9f..9160e34 100644 --- a/src/siteGen/index.js +++ b/src/siteGen/index.js @@ -1,4 +1,4 @@ -import { readFileSync, writeFileSync, copyFileSync } from "fs"; +import { readFileSync, writeFileSync, copyFileSync } from 'fs'; import { dirname, join } from 'path'; import { fileURLToPath } from 'url'; @@ -9,40 +9,49 @@ const __dirname = dirname(fileURLToPath(import.meta.url)); const genAuthors = (a) => { let authors = []; - if (typeof a === "string") { + if (typeof a === 'string') { authors = a.split(', '); } else if (Array.isArray(a)) { authors = a; - }; - - return authors.map((x, i) => { - if (typeof x === 'object') { // User object - const pfp = ``; - const name = `${x.n}`; //#${result.discriminator}`; + } - return i > 1 ? pfp : pfp + name; - } - - let idMatch = x.match(/(.*) \(([0-9]{17,18})\)/); // " ()" - if (idMatch === null) return `${x}`; // "" + return authors + .map((x, i) => { + if (typeof x === 'object') { + // User object + const pfp = ``; + const name = `${x.n}`; //#${result.discriminator}`; - return `${idMatch[1]}`; - }).join(', '); + return i > 1 ? pfp : pfp + name; + } + + let idMatch = x.match(/(.*) \(([0-9]{17,18})\)/); // " ()" + if (idMatch === null) return `${x}`; // "" + + return `${idMatch[1]}`; + }) + .join(', '); }; const makeCard = (m) => { const authors = genAuthors(m.authors); -return `
+ return `
${authors}
${m.name}
-
${m.description}
+
${ + m.description + }
${m.github.stars}
-
${m.version === '0' || m.version.toLowerCase().includes('auto') ? '' : `v${m.version}`}
+
${ + m.version === '0' || m.version.toLowerCase().includes('auto') ? '' : `v${m.version}` + }
`; }; @@ -78,7 +87,8 @@ export default () => { const json = JSON.parse(readFileSync(repo, 'utf8')); - if (repos.length === 1) { // 1 repo likely means a custom repo, so use that name and description + if (repos.length === 1) { + // 1 repo likely means a custom repo, so use that name and description name = json.meta.name; description = `${json.meta.description} `; } @@ -91,23 +101,41 @@ export default () => { themes: json.modules.filter((x) => x.tags.includes('theme')).length, plugins: json.modules.filter((x) => !x.tags.includes('theme')).length, - developers: Object.keys(json.modules.reduce((acc, x) => { (!Array.isArray(x.authors) ? [ x.authors ] : x.authors).forEach((a) => acc[typeof a === 'object' ? a.i : a] = true); return acc; }, {})).length, + developers: Object.keys( + json.modules.reduce((acc, x) => { + (!Array.isArray(x.authors) ? [x.authors] : x.authors).forEach( + (a) => (acc[typeof a === 'object' ? a.i : a] = true), + ); + return acc; + }, {}), + ).length, - filename: repo.split('/').pop() + filename: repo.split('/').pop(), }); } - description += `Browse ${cards.filter((x) => x.tags.includes('theme')).length} themes and ${cards.filter((x) => !x.tags.includes('theme')).length} plugins from ${Object.keys(cards.reduce((acc, x) => { (!Array.isArray(x.authors) ? [ x.authors ] : x.authors).forEach((a) => acc[typeof a === 'object' ? a.i : a] = true); return acc; }, {})).length} developers.`; + description += `Browse ${cards.filter((x) => x.tags.includes('theme')).length} themes and ${ + cards.filter((x) => !x.tags.includes('theme')).length + } plugins from ${ + Object.keys( + cards.reduce((acc, x) => { + (!Array.isArray(x.authors) ? [x.authors] : x.authors).forEach( + (a) => (acc[typeof a === 'object' ? a.i : a] = true), + ); + return acc; + }, {}), + ).length + } developers.`; cards = cards.sort((a, b) => a.name.localeCompare(b.name)).map((x) => makeCard(x)); template = template - .replace('ALL_CARDS', cards.join('\n')) - .replace('REPOS', metas.map((x) => makeRepo(x)).join('\n')) - .replaceAll('NAME', name) - .replaceAll('DESCRIPTION', description); + .replace('ALL_CARDS', cards.join('\n')) + .replace('REPOS', metas.map((x) => makeRepo(x)).join('\n')) + .replace(/NAME/g, name) + .replace(/DESCRIPTION/g, description); writeFileSync(join(global.distDir, 'index.html'), template); copyFileSync(join(__dirname, 'NotoSans-Medium.ttf'), join(global.distDir, 'NotoSans-Medium.ttf')); -}; \ No newline at end of file +};