From 3b161451fb7c87b571276022b5817a43039d6492 Mon Sep 17 00:00:00 2001 From: DefectingCat Date: Thu, 18 May 2023 09:33:43 +0800 Subject: [PATCH] add build content --- scripts/gh-pages/build.mjs | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/scripts/gh-pages/build.mjs b/scripts/gh-pages/build.mjs index b06b397..cced477 100644 --- a/scripts/gh-pages/build.mjs +++ b/scripts/gh-pages/build.mjs @@ -1,8 +1,39 @@ /* @ts-check */ import path from 'path'; +import fs from 'fs/promises'; import { fileURLToPath } from 'url'; +import { log } from 'console'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); -console.log(__dirname); \ No newline at end of file +const contentPath = path.resolve(__dirname, '../../content/posts'); +const buildPath = path.resolve(__dirname, '../../build'); + +async function allPosts() { + const content = await fs.readdir(contentPath); + return content; +} + +async function main() { + const posts = await allPosts(); + + log('Clean build path'); + try { + await fs.access(buildPath); + await fs.rm(buildPath, { recursive: true, force: true }); + } catch (error) {} + + await fs.mkdir(buildPath); + + log('Start build'); + const builds = posts.map((post) => { + log(`Copy file ${post}`); + return fs.copyFile(`${contentPath}/${post}`, `${buildPath}/${post}`); + }); + await Promise.all(builds); + + log('Build done'); +} + +main(); \ No newline at end of file