Fix coerce.date to PST time

This commit is contained in:
Timothy Pidashev
2025-01-14 14:41:07 -08:00
parent a24fea8f3b
commit 8bb28cffa6
3 changed files with 16 additions and 7 deletions

View File

@@ -7,7 +7,9 @@ export const collections = {
description: z.string(),
author: z.string(),
tags: z.array(z.string()),
date: z.coerce.date(),
date: z.coerce.date().transform((date) => {
return new Date(date.setUTCHours(12, 0, 0, 0));
}),
image: z.string().optional(),
imagePosition: z.string().optional(),
}),

View File

@@ -17,7 +17,7 @@ export async function getStaticPaths() {
...post,
data: {
...post.data,
date: new Date(post.data.date).toLocaleDateString("en-US", {
date: post.data.date.toLocaleDateString("en-US", {
year: "numeric",
month: "long",
day: "numeric"

View File

@@ -2,18 +2,25 @@
import { getCollection } from "astro:content";
import ContentLayout from "@/layouts/content.astro";
import { BlogPostList } from "@/components/blog/post-list";
const posts = (await getCollection("blog", ({ data }) => {
return data.isDraft !== true;
})).sort((a, b) => {
return new Date(b.data.date).valueOf() - new Date(a.data.date).valueOf()
});
return b.data.date.valueOf() - a.data.date.valueOf()
}).map(post => ({
...post,
data: {
...post.data,
date: post.data.date.toLocaleDateString("en-US", {
year: "numeric",
month: "long",
day: "numeric"
})
}
}));
---
<ContentLayout
title="Blog | Timothy Pidashev"
description="My experiences and technical insights into software development and the ever-evolving world of programming."
>
<BlogPostList posts={posts} client:load />
</ContentLayout>