From 1f1d0b66daa861a152168b182248777d9dd00b18 Mon Sep 17 00:00:00 2001 From: satr14 Date: Mon, 13 Jul 2026 17:48:27 +0700 Subject: [PATCH] frontmatter standard --- index.ts | 14 +++++++++++--- posts | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/index.ts b/index.ts index 0e79e57..6749be7 100644 --- a/index.ts +++ b/index.ts @@ -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, diff --git a/posts b/posts index a6bc30e..6ddb36d 160000 --- a/posts +++ b/posts @@ -1 +1 @@ -Subproject commit a6bc30e4abc671595fd847cb64931373f09bcd4b +Subproject commit 6ddb36d446ca999d389a8c9578bd5b0c56ec3472