`lib/blog.ts:117-120` falls back to `cache = []` when `POSTS_DIR` is absent:
```ts
if (!fs.existsSync(POSTS_DIR)) {
cache = [];
return cache;
}
```
`:122-132` similarly falls through when the directory has no `.mdx?` files.
Failure mode
If `content/blog/` is deleted, mis-renamed, or absent in a deploy artifact (gitignore mistake, pruned build context), the blog index renders "nothing yet.", the sitemap omits all post URLs, and `generateStaticParams` returns `[]` so no post pages are emitted. CI passes; prod silently regresses to an empty blog.
The directory's presence is part of the project's contract — `app/blog/page.tsx` and `app/sitemap-pages.xml/route.ts` are statically wired up, so a missing directory is a build-config error, not a normal state.
Fix
Throw with an actionable message; leave a `.gitkeep` escape hatch for the legitimate empty case:
```ts
if (!fs.existsSync(POSTS_DIR)) {
throw new Error(
`[blog] posts directory not found at ${POSTS_DIR}. ` +
`If you intentionally have zero posts, create the directory with a .gitkeep.`,
);
}
```
Optionally apply the same to the "directory present but no .mdx files" case, or at minimum log the post count during build so an unexpected zero shows up in CI logs.
Found during PR review of #61.
`lib/blog.ts:117-120` falls back to `cache = []` when `POSTS_DIR` is absent:
```ts
if (!fs.existsSync(POSTS_DIR)) {
cache = [];
return cache;
}
```
`:122-132` similarly falls through when the directory has no `.mdx?` files.
Failure mode
If `content/blog/` is deleted, mis-renamed, or absent in a deploy artifact (gitignore mistake, pruned build context), the blog index renders "nothing yet.", the sitemap omits all post URLs, and `generateStaticParams` returns `[]` so no post pages are emitted. CI passes; prod silently regresses to an empty blog.
The directory's presence is part of the project's contract — `app/blog/page.tsx` and `app/sitemap-pages.xml/route.ts` are statically wired up, so a missing directory is a build-config error, not a normal state.
Fix
Throw with an actionable message; leave a `.gitkeep` escape hatch for the legitimate empty case:
```ts
if (!fs.existsSync(POSTS_DIR)) {
throw new Error(
`[blog] posts directory not found at ${POSTS_DIR}. ` +
`If you intentionally have zero posts, create the directory with a .gitkeep.`,
);
}
```
Optionally apply the same to the "directory present but no .mdx files" case, or at minimum log the post count during build so an unexpected zero shows up in CI logs.
Found during PR review of #61.