Fix post sorting when a post has an unquoted published date

Merged
Opened by dwinrick

utils/posts.util.ts declares published?: string, but an unquoted published: 2026-06-04 in frontmatter is a YAML date, so gray-matter returns a Date. The sort then calls .localeCompare on a Date and throws:

  TypeError: (b.published ?? "").localeCompare is not a function
      at utils/posts.util.ts:33:25
      

It doesn't show up in the template as shipped, because Array.sort never calls the comparator with a single post. Add a second post to a fresh remix and the index 500s. I hit this within a minute of adding my second post.

The same root cause puts a full timestamp in <time datetime>: datetime="Thu Jun 04 2026 00:00:00 GMT+0000 (Coordinated Universal Time)" instead of 2026-06-04.

This normalizes published to YYYY-MM-DD at parse time, fixing both. Quoting the date in the example post would also fix the crash, but then every new post is one unquoted date away from the same failure.

1 file changed
+9
-1

Pull request merged