mirror of
https://github.com/KazooTTT/kazoottt-blog.git
synced 2025-06-22 02:01:32 +08:00
feat: use date not publishDate
This commit is contained in:
@ -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>
|
||||
)
|
||||
}
|
||||
} -->
|
||||
|
@ -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'>
|
||||
|
@ -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(),
|
||||
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: 如何在 Cursor 中使用 DeepSeek-Coder
|
||||
publishDate: 2024-07-25
|
||||
date: 2024-07-25
|
||||
author: KazooTTT
|
||||
type: Post
|
||||
status: Draft
|
||||
|
@ -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()
|
||||
---
|
||||
|
||||
|
@ -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}`
|
||||
}))
|
||||
})
|
||||
|
@ -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>)
|
||||
}
|
||||
|
Reference in New Issue
Block a user