Skip to content

lib/blog.ts silently produces an empty blog when content/blog/ is missing or empty #66

Description

@thiras

`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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions