frontmatter standard
All checks were successful
Build and Deploy / deploy (push) Successful in 54s

This commit is contained in:
Satria 2026-07-13 17:48:27 +07:00
commit 1f1d0b66da
2 changed files with 12 additions and 4 deletions

View file

@ -26,6 +26,7 @@ const defaultFrontmatter = {
desc: "",
date: "0000-00-00", // YYYY-MM-DD
draft: true,
skip: false,
};
function fetchFrontmatter(raw?: string) {
@ -40,10 +41,17 @@ function fetchFrontmatter(raw?: string) {
}
await Promise.all(posts.map(async (post) => {
const raw = (await Bun.file(`./posts/${post}`).text()).split("^---");
if (!post.endsWith(".md")) return;
const raw = await Bun.file(`./posts/${post}`).text();
const lines = raw.split("\n");
const content = raw.at(-1) || "_No content_";
const frontmatter = fetchFrontmatter(raw.at(0));
const closingIndex = lines[0] === "---" ? lines.indexOf("---", 1) : -1;
const frontmatterRaw = closingIndex > 0 ? lines.slice(1, closingIndex).join("\n") : undefined;
const contentRaw = closingIndex > 0 ? lines.slice(closingIndex + 1).join("\n") : raw;
const frontmatter = fetchFrontmatter(frontmatterRaw);
if (frontmatter.skip) return;
const content = contentRaw || "_No content_";
const html = Bun.markdown.html(content, {
autolinks: true,