Skip to content

Coerce YAML Date frontmatter to a date string - #21

Open
CharanMN7 wants to merge 1 commit into
mainfrom
fix/frontmatter-date-coercion
Open

Coerce YAML Date frontmatter to a date string#21
CharanMN7 wants to merge 1 commit into
mainfrom
fix/frontmatter-date-coercion

Conversation

@CharanMN7

Copy link
Copy Markdown
Contributor

Fixes #20

loadBlogPosts/loadBlogPost/loadChangelogEntries parsed frontmatter dates
with typeof data.date === 'string' ? data.date.slice(0, 10) : ''. An
unquoted date: 2026-01-25 is parsed by gray-matter (via js-yaml, per the
YAML spec's !!timestamp type) as a native Date, not a string — so that
check dropped the date to ''. Effects: the post sorts last, and anything
rendering the date shows "Invalid Date". No build warning, easy to ship
without noticing.

Fix

Added toDateString() — accepts either a string (existing .slice(0, 10)
behavior, unchanged) or a Date instance (formats as UTC YYYY-MM-DD).
Used in both toBlogPost() and loadChangelogEntries().

Testing

Added packages/framework/src/content.test.ts — real MDX fixtures on disk
(via DOCS_CONTENT_ROOT), covering an unquoted date, a quoted date, sort
order between the two, a changelog entry, and the missing-date fallback.
npx vitest run (99/99 passing) and npx tsc --noEmit both clean.

Not in scope here

This doesn't touch the blog guide's example frontmatter (still shows
date: 2026-09-05 unquoted) — now harmless either way, so no doc change
needed. Sites already on an affected published version (ai-charan-dev and
likely others) will pick up the fix on their next @inkform/framework
bump once this is released.

🤖 Generated with Claude Code

https://claude.ai/code/session_01E4mKgFidjkjdxyCziBsNnJ

An unquoted `date: 2026-01-25` in frontmatter is parsed by gray-matter
(via js-yaml) as a native Date, not a string. The loader's bare
`typeof === 'string'` check dropped that to '', so the post sorted
last and rendered "Invalid Date" downstream — silently, with no build
warning. Several live sites (ai-charan-dev and likely others) have
this today since nothing in the blog guide says to quote the date.

Fixes #20

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01E4mKgFidjkjdxyCziBsNnJ
@vercel

vercel Bot commented Sep 9, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Actions Updated
framework-inkform-docs Skipped Skipped Sep 9, 2026 2:32am UTC
pokeapi Skipped Skipped Sep 9, 2026 2:32am UTC

Request Review

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unquoted YAML frontmatter date silently becomes '' (sorts last, renders Invalid Date)

1 participant