feat: use date not publishDate

This commit is contained in:
KazooTTT
2024-07-25 17:48:35 +08:00
parent 0b8b30c99c
commit d99e484aa9
7 changed files with 21 additions and 18 deletions

View File

@ -34,7 +34,7 @@ const dateTimeOptions: Intl.DateTimeFormatOptions = {
{data.draft ? <span class='text-red-500'>(Draft)</span> : null}
<div class='flex flex-wrap items-center gap-x-3 gap-y-2'>
<p class='text-xs'>
<FormattedDate date={data.publishDate} dateTimeOptions={dateTimeOptions} /> /{' '}
<FormattedDate date={data.date} dateTimeOptions={dateTimeOptions} /> /{' '}
{remarkPluginFrontmatter.minutesRead}
</p>
</div>
@ -79,11 +79,11 @@ const dateTimeOptions: Intl.DateTimeFormatOptions = {
)
}
{
data.updatedDate && (
<!-- {
data.date && (
<p class='mt-6 text-base'>
Last Updated:
<FormattedDate class='ms-1' date={data.updatedDate} dateTimeOptions={dateTimeOptions} />
<FormattedDate class='ms-1' date={data.date} dateTimeOptions={dateTimeOptions} />
</p>
)
}
} -->

View File

@ -10,7 +10,7 @@ type Props<Tag extends HTMLTag> = Polymorphic<{ as: Tag }> & {
}
const { as: Tag = 'div', post, withDesc = false } = Astro.props
const postDate = post.data.updatedDate ?? post.data.publishDate
const postDate = post.data.date
---
<li class='flex flex-col gap-2 sm:flex-row sm:gap-x-4 [&_q]:basis-full'>

View File

@ -13,14 +13,10 @@ const post = defineCollection({
z.object({
title: z.string().max(60),
description: z.string(),
publishDate: z
date: z
.string()
.or(z.date())
.transform((val) => new Date(val)),
updatedDate: z
.string()
.optional()
.transform((str) => (str ? new Date(str) : undefined)),
coverImage: z
.object({
src: image(),

View File

@ -1,6 +1,6 @@
---
title: 如何在 Cursor 中使用 DeepSeek-Coder
publishDate: 2024-07-25
date: 2024-07-25
author: KazooTTT
type: Post
status: Draft

View File

@ -13,12 +13,12 @@ interface Props {
const { post } = Astro.props
const {
data: { description, ogImage, publishDate, title, updatedDate },
data: { description, ogImage, title, date },
slug
} = post
const socialImage = ogImage ?? `/og-image/${slug}.png`
const articleDate = updatedDate?.toISOString() ?? publishDate.toISOString()
const articleDate = date?.toISOString()
const { headings } = await post.render()
---

View File

@ -12,7 +12,7 @@ export const GET = async () => {
items: posts.map((post) => ({
title: post.data.title,
description: post.data.description,
pubDate: post.data.publishDate,
pubDate: post.data.date,
link: `/blog/${post.slug}`
}))
})

View File

@ -10,8 +10,8 @@ export async function getAllPosts() {
export function sortMDByDate(posts: Array<CollectionEntry<'post'>>) {
return posts.sort((a, b) => {
const aDate = new Date(a.data.updatedDate ?? a.data.publishDate).valueOf()
const bDate = new Date(b.data.updatedDate ?? b.data.publishDate).valueOf()
const aDate = new Date(a.data.date).valueOf()
const bDate = new Date(b.data.date).valueOf()
return bDate - aDate
})
}
@ -59,4 +59,11 @@ export function getUniqueCategoriesWithCount(
new Map<string, number>()
)
].sort((a, b) => b[1] - a[1])
}
}
export function getIdToSlugMap(posts: Array<CollectionEntry<'post'>>) {
return posts.reduce((acc, post) => {
acc[(post.id.split(".md")[0])] = post.slug
return acc
}, {} as Record<string, string>)
}