diff --git a/src/index.js b/src/index.js index 59b6bde..b881156 100644 --- a/src/index.js +++ b/src/index.js @@ -3,13 +3,14 @@ import ModuleRepos from './modules/index.js'; import AutoTag from './autoTag.js'; import WebhookSend from './webhook.js'; import ImageCDN from './imageCdn.js'; -import authorGen from './authorGen.js'; +import AuthorGen from './authorGen.js'; +import SiteGen from './siteGen/index.js'; import Parcel from 'parcel-bundler'; import axios from 'axios'; import glob from 'glob'; -import { rmSync, mkdirSync, readFileSync, writeFileSync, copyFileSync, existsSync } from 'fs'; +import { rmSync, mkdirSync, readFileSync, writeFileSync, existsSync } from 'fs'; import { createHash } from 'crypto'; import { dirname, sep } from 'path'; @@ -88,8 +89,6 @@ const getGithubInfo = async (repo) => { return info; }; -let oldTotalModulesJson = []; - for (const parentRepo of ModuleRepos) { let moduleJson = { modules: [], @@ -224,7 +223,7 @@ for (const parentRepo of ModuleRepos) { if (Array.isArray(manifestJson.authors)) manifestJson.authors = await Promise.all(manifestJson.authors.map(async (x) => { if (x.match(/^[0-9]{17,18}$/)) { - return await authorGen(x); + return await AuthorGen(x); } return x; @@ -244,10 +243,9 @@ for (const parentRepo of ModuleRepos) { moduleJson.modules = moduleJson.modules.filter((x) => x !== null); writeFileSync(repoJsonPath, JSON.stringify(moduleJson)); - - oldTotalModulesJson = oldTotalModulesJson.concat(moduleJson.modules); } +<<<<<<< HEAD writeFileSync(`${distDir}/modules.json`, JSON.stringify(oldTotalModulesJson)); <<<<<<< HEAD @@ -257,3 +255,6 @@ WebhookSend(); ======= copyFileSync(`${__dirname.replace(`${sep}src`, '')}/_headers`, `${distDir}/_headers`); >>>>>>> 66b474c (Fix error on Windows (#9)) +======= +await SiteGen(); +>>>>>>> 736a0e1 ([SiteGen] Initial add (also remove deprecated modules.json)) diff --git a/src/siteGen/NotoSans-Medium.ttf b/src/siteGen/NotoSans-Medium.ttf new file mode 100644 index 0000000..0693449 Binary files /dev/null and b/src/siteGen/NotoSans-Medium.ttf differ diff --git a/src/siteGen/index.js b/src/siteGen/index.js new file mode 100644 index 0000000..af527b5 --- /dev/null +++ b/src/siteGen/index.js @@ -0,0 +1,75 @@ +import { readFileSync, writeFileSync, copyFileSync } from "fs"; + +import { dirname, join } from 'path'; +import { fileURLToPath } from 'url'; + +import glob from 'glob'; + +const __dirname = dirname(fileURLToPath(import.meta.url)); + +const genAuthors = (a) => { + let authors = []; + + 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 `${idMatch[1]}`; + }).join(', '); +}; + +const makeCard = (m) => { + const authors = genAuthors(m.authors); +return `
+
+
${authors}
+
${m.name}
+
${m.description}
+
+
+ ${m.github.stars} + +
+
${m.version === '0' || m.version.toLowerCase().includes('auto') ? '' : `v${m.version}`}
+
+
`; +} + +export default () => { + let template = readFileSync(join(__dirname, 'template.html'), 'utf8'); + + const repos = glob.sync(join(global.distDir, '*.json')); + + let cards = []; + + for (const repo of repos) { + const repoName = repo.split('/').pop().split('.')[0]; + console.log(repo, repoName); + + const json = JSON.parse(readFileSync(repo, 'utf8')); + console.log(json); + + cards = cards.concat(json.modules); + } + + cards = cards.sort((a, b) => a.name.localeCompare(b.name)).map((x) => makeCard(x)); + + template = template.replace('ALL_CARDS', cards.join('\n')); + + 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 diff --git a/src/siteGen/template.html b/src/siteGen/template.html new file mode 100644 index 0000000..98813f1 --- /dev/null +++ b/src/siteGen/template.html @@ -0,0 +1,389 @@ + + + + GooseMod Store + + + + + + + +
+ + +
+
Sort by
+ +
+ +
+ + ALL_CARDS +
+ + + + \ No newline at end of file