This commit is contained in:
parent
a9ac9d3eac
commit
1f1d0b66da
2 changed files with 12 additions and 4 deletions
14
index.ts
14
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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue