From 718979fd046fd3bf72b13b49202625f18ac22b93 Mon Sep 17 00:00:00 2001 From: Nir Galon Date: Sun, 9 Oct 2022 00:24:00 +0300 Subject: [PATCH] ci: build index script --- index-posts.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/index-posts.js b/index-posts.js index 8d825b8..5c4d63c 100644 --- a/index-posts.js +++ b/index-posts.js @@ -4,15 +4,16 @@ import matter from "gray-matter"; const postsPath = await globby(["src/pages/blog"]); -const objects = postsPath.map((postPath) => { +const objects = []; +for (const postPath of postsPath) { if (postPath.endsWith(".md")) { const fileContents = fs.readFileSync(postPath, "utf8"); const { data, content } = matter(fileContents); - if (Boolean(data.draft) == false) { + if (!(data.draft && Boolean(data.draft))) { const slug = postPath.replace(".md", "").replace("src/pages/", ""); - return { + objects.push({ title: data.title, author: data.author, tags: data.tags, @@ -20,9 +21,10 @@ const objects = postsPath.map((postPath) => { date: data.pubDate, slug: slug, content: content, - }; + }); } } -}); +} -fs.writeFileSync("dist/index.json", objects); +fs.mkdirSync("dist", { recursive: true }); +fs.writeFileSync("dist/index.json", JSON.stringify(objects), "utf8");