Skip to content

Commit

Permalink
ci: build index script
Browse files Browse the repository at this point in the history
  • Loading branch information
Nir Galon committed Oct 8, 2022
1 parent 0a74312 commit 718979f
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions index-posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,27 @@ 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,
category: data.category,
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");

0 comments on commit 718979f

Please sign in to comment.