feat: assemble final post text
Co-Authored-By: Claude
This commit is contained in:
14
src/buildPost.test.ts
Normal file
14
src/buildPost.test.ts
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import { expect, test } from "vitest";
|
||||||
|
import { buildPost } from "./buildPost";
|
||||||
|
|
||||||
|
test("assembles frontmatter + body with single trailing newline", () => {
|
||||||
|
const out = buildPost({
|
||||||
|
frontmatterPairs: [{ key: "layout", value: "post" }],
|
||||||
|
body: "Hello world",
|
||||||
|
});
|
||||||
|
expect(out).toBe("---\nlayout: post\n---\n\nHello world\n");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("empty frontmatter still emits a delimiter block", () => {
|
||||||
|
expect(buildPost({ frontmatterPairs: [], body: "x" })).toBe("---\n\n---\n\nx\n");
|
||||||
|
});
|
||||||
7
src/buildPost.ts
Normal file
7
src/buildPost.ts
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
import { Pair, serializeFrontmatter } from "./frontmatter";
|
||||||
|
|
||||||
|
export function buildPost(o: { frontmatterPairs: Pair[]; body: string }): string {
|
||||||
|
const fm = serializeFrontmatter(o.frontmatterPairs);
|
||||||
|
const body = o.body.replace(/\s+$/, "");
|
||||||
|
return `${fm}\n${body}\n`;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user