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