[siteGen] Fix replaceAll bug
This commit is contained in:
parent
4879b52251
commit
bd4c9d266a
|
@ -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 = `<img loading=lazy style="display: inline; border-radius: 50%; margin-right: 5px; vertical-align: bottom;" src="https://cdn.discordapp.com/avatars/${x.i}/${x.a}.png?size=32">`;
|
||||
const name = `<span class="author" style="line-height: 32px;">${x.n}</span>`; //<span class="description-3_Ncsb">#${result.discriminator}</span></span>`;
|
||||
}
|
||||
|
||||
return i > 1 ? pfp : pfp + name;
|
||||
}
|
||||
|
||||
let idMatch = x.match(/(.*) \(([0-9]{17,18})\)/); // "<name> (<id>)"
|
||||
if (idMatch === null) return `<span class="author">${x}</span>`; // "<name>"
|
||||
return authors
|
||||
.map((x, i) => {
|
||||
if (typeof x === 'object') {
|
||||
// User object
|
||||
const pfp = `<img loading=lazy style="display: inline; border-radius: 50%; margin-right: 5px; vertical-align: bottom;" src="https://cdn.discordapp.com/avatars/${x.i}/${x.a}.png?size=32">`;
|
||||
const name = `<span class="author" style="line-height: 32px;">${x.n}</span>`; //<span class="description-3_Ncsb">#${result.discriminator}</span></span>`;
|
||||
|
||||
return `<span class="author">${idMatch[1]}</span>`;
|
||||
}).join('<span class="description-3_Ncsb">,</span> ');
|
||||
return i > 1 ? pfp : pfp + name;
|
||||
}
|
||||
|
||||
let idMatch = x.match(/(.*) \(([0-9]{17,18})\)/); // "<name> (<id>)"
|
||||
if (idMatch === null) return `<span class="author">${x}</span>`; // "<name>"
|
||||
|
||||
return `<span class="author">${idMatch[1]}</span>`;
|
||||
})
|
||||
.join('<span class="description-3_Ncsb">,</span> ');
|
||||
};
|
||||
|
||||
const makeCard = (m) => {
|
||||
const authors = genAuthors(m.authors);
|
||||
return `<div class="gm-store-card ${m.tags.join(' ')}" data-last-updated=${m.lastUpdated} data-stars=${m.github.stars}>
|
||||
return `<div class="gm-store-card ${m.tags.join(' ')}" data-last-updated=${
|
||||
m.lastUpdated
|
||||
} data-stars=${m.github.stars}>
|
||||
<div style="background-image: url('${m.images?.length ? m.images[0] : ''}');"></div>
|
||||
<div class="title-31JmR4 ${!authors.includes('avatar') ? 'no-pfp' : ''}">${authors}</div>
|
||||
<div class="title-31JmR4">${m.name}</div>
|
||||
<div class="colorStandard-2KCXvj size14-e6ZScH default-3nhoK- formText-3fs7AJ description-3_Ncsb formText-3fs7AJ modeDefault-3a2Ph1">${m.description}</div>
|
||||
<div class="colorStandard-2KCXvj size14-e6ZScH default-3nhoK- formText-3fs7AJ description-3_Ncsb formText-3fs7AJ modeDefault-3a2Ph1">${
|
||||
m.description
|
||||
}</div>
|
||||
<div>
|
||||
<div class="colorStandard-2KCXvj size14-e6ZScH default-3nhoK- formText-3fs7AJ description-3_Ncsb formText-3fs7AJ modeDefault-3a2Ph1">
|
||||
<span>${m.github.stars}</span>
|
||||
<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor"><path d="M12 .587l3.668 7.568 8.332 1.151-6.064 5.828 1.48 8.279-7.416-3.967-7.417 3.967 1.481-8.279-6.064-5.828 8.332-1.151z"></path></svg>
|
||||
</div>
|
||||
<div class="colorStandard-2KCXvj size14-e6ZScH default-3nhoK- formText-3fs7AJ description-3_Ncsb formText-3fs7AJ modeDefault-3a2Ph1">${m.version === '0' || m.version.toLowerCase().includes('auto') ? '' : `v${m.version}`}</div>
|
||||
<div class="colorStandard-2KCXvj size14-e6ZScH default-3nhoK- formText-3fs7AJ description-3_Ncsb formText-3fs7AJ modeDefault-3a2Ph1">${
|
||||
m.version === '0' || m.version.toLowerCase().includes('auto') ? '' : `v${m.version}`
|
||||
}</div>
|
||||
</div>
|
||||
</div>`;
|
||||
};
|
||||
|
@ -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'));
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue