update build gh-pages script

This commit is contained in:
DefectingCat
2023-05-19 09:04:55 +08:00
parent 4e5a72df99
commit 7db51d51a7

View File

@ -10,13 +10,32 @@ const __dirname = path.dirname(__filename);
const contentPath = path.resolve(__dirname, '../../content/posts'); const contentPath = path.resolve(__dirname, '../../content/posts');
const buildPath = path.resolve(__dirname, '../../build'); const buildPath = path.resolve(__dirname, '../../build');
const PostPerPage = 10;
/**
* Read post folder, list all posts
*/
async function allPosts() { async function allPosts() {
const content = await fs.readdir(contentPath); const content = await fs.readdir(contentPath);
return content; return content;
} }
/**
* Copy all posts to build folder
*/
async function copyPosts(posts) {
const builds = posts.map((post) => {
log(`Copy file ${post}`);
return fs.copyFile(`${contentPath}/${post}`, `${buildPath}/${post}`);
});
await Promise.all(builds);
}
async function buildJson(posts) {}
async function main() { async function main() {
const posts = await allPosts(); const posts = await allPosts();
log(posts);
log('Clean build path'); log('Clean build path');
try { try {
@ -27,11 +46,8 @@ async function main() {
await fs.mkdir(buildPath); await fs.mkdir(buildPath);
log('Start build'); log('Start build');
const builds = posts.map((post) => { await copyPosts(posts);
log(`Copy file ${post}`);
return fs.copyFile(`${contentPath}/${post}`, `${buildPath}/${post}`);
});
await Promise.all(builds);
log('Build done'); log('Build done');
} }