From b6f9b268d85a400b2cbcd52ac6ebb511fc6e35dd Mon Sep 17 00:00:00 2001 From: Hykilpikonna Date: Fri, 8 Apr 2022 17:38:52 -0400 Subject: [PATCH] [+] Build comments --- scripts/build.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/scripts/build.ts b/scripts/build.ts index a76f67ee..3813925f 100644 --- a/scripts/build.ts +++ b/scripts/build.ts @@ -9,6 +9,7 @@ import { renderMdx } from "./mdx.ts"; const PUBLIC_DIR = "public"; const PEOPLE_DIR = "people"; +const COMMENTS_DIR = "comments"; const PEOPLE_INFO_FILENAME = "info.json5"; const PEOPLE_PAGE_FILE = "page.md"; @@ -37,6 +38,7 @@ function buildPeopleInfoAndList() { const infoFile = fs.readFileSync(path.join(srcPath, PEOPLE_INFO_FILENAME), "utf-8"); const info = json5.parse(infoFile); + // Add meta information const peopleMeta = { path: dirname, ...Object.fromEntries(PEOPLE_LIST_KEYS.map(key => [key, info[key]])) @@ -44,10 +46,19 @@ function buildPeopleInfoAndList() { peopleList.push(peopleMeta); + // Combine comments in people/${dirname}/comments/${cf}.json + const commentPath = path.join(srcPath, COMMENTS_DIR) + fs.ensureDirSync(commentPath) + info.comments = fs.readdirSync(commentPath) + .filter(cf => cf.endsWith('.json')) + .map(cf => JSON.parse(fs.readFileSync(path.join(commentPath, cf), 'utf-8'))) + + // Write info.json fs.ensureDirSync(distPath); fs.writeFileSync(path.join(distPath, DIST_PEOPLE_INFO_FILENAME), JSON.stringify(info)); } + // Write people-list.json fs.writeFileSync(path.join(projectRoot, DIST_DIR, DIST_PEOPLE_LIST), JSON.stringify(peopleList)); } @@ -62,9 +73,9 @@ function buildPeoplePages() { } } -// Copy `people/${dirname}/comments` and `photos` to `dist/people/${dirname}/`. +// Copy `people/${dirname}/photos` to `dist/people/${dirname}/`. function copyPeopleAssets() { - const PEOPLE_ASSETS = ["comments", "photos"]; + const PEOPLE_ASSETS = ["photos"]; for (const { srcPath, distPath } of people) { fs.ensureDirSync(distPath);