1
0
mirror of https://github.com/one-among-us/data.git synced 2024-11-22 19:24:51 +08:00

[O] Use list

This commit is contained in:
Elihuso Quigley 2024-03-17 15:57:18 +08:00
parent a08c2c6320
commit cd771e609a
3 changed files with 30 additions and 20 deletions

3
data/comment-only.json Normal file
View File

@ -0,0 +1,3 @@
[
"tdor"
]

1
data/exclude.json Normal file
View File

@ -0,0 +1 @@
[]

View File

@ -17,6 +17,8 @@ const COMMENTS_DIR = "comments";
const DIST_DIR = "dist"; const DIST_DIR = "dist";
const DATA_DIR = "data";
const projectRoot = path.dirname(path.dirname(url.fileURLToPath(import.meta.url))); const projectRoot = path.dirname(path.dirname(url.fileURLToPath(import.meta.url)));
const peopleDir = path.join(projectRoot, PEOPLE_DIR); const peopleDir = path.join(projectRoot, PEOPLE_DIR);
const people = fs.readdirSync(peopleDir).map(person => ({ const people = fs.readdirSync(peopleDir).map(person => ({
@ -25,6 +27,9 @@ const people = fs.readdirSync(peopleDir).map(person => ({
distPath: path.join(projectRoot, DIST_DIR, PEOPLE_DIR, person) distPath: path.join(projectRoot, DIST_DIR, PEOPLE_DIR, person)
})); }));
const commentOnlyList = JSON.parse(fs.readFileSync(path.join(projectRoot, DATA_DIR, "comment-only.json")).toString()) as String[];
const excludeList = commentOnlyList.concat(JSON.parse(fs.readFileSync(path.join(projectRoot, DATA_DIR, 'exclude.json')).toString()) as String[]);
interface PeopleMeta { interface PeopleMeta {
id: string id: string
name: string name: string
@ -48,7 +53,7 @@ function buildPeopleInfoAndList() {
// For each person // For each person
for (const { dirname, srcPath, distPath } of people) { for (const { dirname, srcPath, distPath } of people) {
if (dirname == 'tdor') continue; if (excludeList.includes(dirname)) continue;
const infoFile = fs.readFileSync(path.join(srcPath, `info.yml`), "utf-8"); const infoFile = fs.readFileSync(path.join(srcPath, `info.yml`), "utf-8");
const info: any = YAML.load(infoFile); const info: any = YAML.load(infoFile);
@ -119,7 +124,9 @@ function buildPeopleInfoAndList() {
// Render `people/${dirname}/page.md` to `dist/people/${dirname}/page.js`. // Render `people/${dirname}/page.md` to `dist/people/${dirname}/page.js`.
function buildPeoplePages() { function buildPeoplePages() {
for (const { dirname, srcPath, distPath } of people) { for (const { dirname, srcPath, distPath } of people) {
if (dirname == 'tdor') continue;
if (excludeList.includes(dirname)) continue;
for (const lang of ['', '.zh_hant', '.en']) for (const lang of ['', '.zh_hant', '.en'])
{ {
// Read markdown page and remove markdown meta // Read markdown page and remove markdown meta
@ -185,30 +192,29 @@ function copyPublic() {
fs.copySync(path.join(projectRoot, PUBLIC_DIR), path.join(projectRoot, DIST_DIR)); fs.copySync(path.join(projectRoot, PUBLIC_DIR), path.join(projectRoot, DIST_DIR));
} }
function copyTDORComments() { function copyComments() {
const commentPath = path.join(peopleDir, 'tdor', COMMENTS_DIR); for (const dirname of commentOnlyList) {
const distPath = path.join(projectRoot, DIST_DIR, PEOPLE_DIR, 'tdor'); const commentPath = path.join(peopleDir, dirname as string, COMMENTS_DIR);
fs.ensureDirSync(commentPath); const distPath = path.join(projectRoot, DIST_DIR, PEOPLE_DIR, dirname as string);
var info = { comments: [] }; fs.ensureDirSync(commentPath);
info.comments = fs var info = { comments: [] };
.readdirSync(commentPath) info.comments = fs
.filter((cf) => cf.endsWith(".json")) .readdirSync(commentPath)
.map((cf) => .filter((cf) => cf.endsWith(".json"))
JSON.parse(fs.readFileSync(path.join(commentPath, cf), "utf-8")) .map((cf) =>
); JSON.parse(fs.readFileSync(path.join(commentPath, cf), "utf-8"))
info.comments.forEach((c) => (c.content = autocorrect.format(c.content))); );
fs.ensureDirSync(distPath); info.comments.forEach((c) => (c.content = autocorrect.format(c.content)));
fs.writeFileSync( fs.ensureDirSync(distPath);
path.join(distPath, 'info.json'), fs.writeFileSync(path.join(distPath, "info.json"), JSON.stringify(info));
JSON.stringify(info) }
);
} }
buildPeopleInfoAndList(); buildPeopleInfoAndList();
buildPeoplePages(); buildPeoplePages();
copyPeopleAssets(); copyPeopleAssets();
copyPublic(); copyPublic();
copyTDORComments(); copyComments();
/** /**
* Trim a specific char from a string * Trim a specific char from a string