Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

fix(app): keep bundle placeholder blog-valid

Gener99824d2d4ad0
diff --git a/src/app/scripts/blog-placeholder.ts b/src/app/scripts/blog-placeholder.ts
new file mode 100644
index 000000000..f35e89fc7
--- /dev/null
+++ b/src/app/scripts/blog-placeholder.ts
@@ -0,0 +1,14 @@
+export const BLOG_PLACEHOLDER_FILENAME = "build-placeholder.mdx";
+
+export const BLOG_PLACEHOLDER_SOURCE = `export const metadata = {
+ slug: "build-placeholder",
+ title: "Placeholder",
+ date: "2020-01-01",
+ author: "Alook",
+ excerpt: "Build-time placeholder; never listed.",
+ readingTime: "1 min read",
+ draft: true,
+};
+
+Placeholder.
+`;
diff --git a/src/app/scripts/bundle.ts b/src/app/scripts/bundle.ts
index 3efbc4078..3927e3c0c 100644
--- a/src/app/scripts/bundle.ts
+++ b/src/app/scripts/bundle.ts
@@ -9,6 +9,7 @@ import { execSync } from "child_process";
import { cpSync, rmSync, mkdirSync, existsSync, readdirSync, readFileSync, writeFileSync } from "fs";
import { join, dirname } from "path";
import { fileURLToPath } from "url";
+import { BLOG_PLACEHOLDER_FILENAME, BLOG_PLACEHOLDER_SOURCE } from "./blog-placeholder";
const __dirname = dirname(fileURLToPath(import.meta.url));
const appRoot = join(__dirname, "..");
@@ -71,16 +72,8 @@ mkdirSync(blogContentDir, { recursive: true });
// error (webpack only warned). Drop one draft placeholder so the glob resolves.
// It never surfaces: getAllPosts() skips `draft: true`, and no route links it.
writeFileSync(
- join(blogContentDir, "_placeholder.mdx"),
- `export const metadata = {\n` +
- ` slug: "_placeholder",\n` +
- ` title: "Placeholder",\n` +
- ` date: "2020-01-01",\n` +
- ` author: "Alook",\n` +
- ` excerpt: "Build-time placeholder; never listed.",\n` +
- ` readingTime: "1 min",\n` +
- ` draft: true,\n` +
- `};\n\nPlaceholder.\n`,
+ join(blogContentDir, BLOG_PLACEHOLDER_FILENAME),
+ BLOG_PLACEHOLDER_SOURCE,
);
try {
@@ -89,7 +82,7 @@ try {
console.log("[bundle] Restoring blog source files...");
try {
// Drop the untracked placeholder, then restore the tracked content/images.
- rmSync(join(blogContentDir, "_placeholder.mdx"), { force: true });
+ rmSync(join(blogContentDir, BLOG_PLACEHOLDER_FILENAME), { force: true });
execSync("git checkout -- src/web/public/blog/ src/web/src/content/", {
cwd: monoRoot,
stdio: "inherit",
diff --git a/src/app/test/blog-placeholder.test.ts b/src/app/test/blog-placeholder.test.ts
new file mode 100644
index 000000000..f55816ee3
--- /dev/null
+++ b/src/app/test/blog-placeholder.test.ts
@@ -0,0 +1,14 @@
+import { describe, expect, it } from "vitest";
+import {
+ BLOG_PLACEHOLDER_FILENAME,
+ BLOG_PLACEHOLDER_SOURCE,
+} from "../scripts/blog-placeholder";
+import { readBlogMetadata } from "../../web/src/lib/blog/validate-assets";
+
+describe("blog bundle placeholder", () => {
+ it("satisfies the blog metadata contract", () => {
+ const fileSlug = BLOG_PLACEHOLDER_FILENAME.replace(/\.mdx$/, "");
+
+ expect(readBlogMetadata(BLOG_PLACEHOLDER_SOURCE, fileSlug).errors).toEqual([]);
+ });
+});