mirror of
https://github.com/KazooTTT/kazoottt-blog.git
synced 2025-06-22 10:11:30 +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}
|
{data.draft ? <span class='text-red-500'>(Draft)</span> : null}
|
||||||
<div class='flex flex-wrap items-center gap-x-3 gap-y-2'>
|
<div class='flex flex-wrap items-center gap-x-3 gap-y-2'>
|
||||||
<p class='text-xs'>
|
<p class='text-xs'>
|
||||||
<FormattedDate date={data.publishDate} dateTimeOptions={dateTimeOptions} /> /{' '}
|
<FormattedDate date={data.date} dateTimeOptions={dateTimeOptions} /> /{' '}
|
||||||
{remarkPluginFrontmatter.minutesRead}
|
{remarkPluginFrontmatter.minutesRead}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
@ -79,11 +79,11 @@ const dateTimeOptions: Intl.DateTimeFormatOptions = {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
<!-- {
|
||||||
data.updatedDate && (
|
data.date && (
|
||||||
<p class='mt-6 text-base'>
|
<p class='mt-6 text-base'>
|
||||||
Last Updated:
|
Last Updated:
|
||||||
<FormattedDate class='ms-1' date={data.updatedDate} dateTimeOptions={dateTimeOptions} />
|
<FormattedDate class='ms-1' date={data.date} dateTimeOptions={dateTimeOptions} />
|
||||||
</p>
|
</p>
|
||||||
)
|
)
|
||||||
}
|
} -->
|
||||||
|
@ -10,7 +10,7 @@ type Props<Tag extends HTMLTag> = Polymorphic<{ as: Tag }> & {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const { as: Tag = 'div', post, withDesc = false } = Astro.props
|
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'>
|
<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({
|
z.object({
|
||||||
title: z.string().max(60),
|
title: z.string().max(60),
|
||||||
description: z.string(),
|
description: z.string(),
|
||||||
publishDate: z
|
date: z
|
||||||
.string()
|
.string()
|
||||||
.or(z.date())
|
.or(z.date())
|
||||||
.transform((val) => new Date(val)),
|
.transform((val) => new Date(val)),
|
||||||
updatedDate: z
|
|
||||||
.string()
|
|
||||||
.optional()
|
|
||||||
.transform((str) => (str ? new Date(str) : undefined)),
|
|
||||||
coverImage: z
|
coverImage: z
|
||||||
.object({
|
.object({
|
||||||
src: image(),
|
src: image(),
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
title: 如何在 Cursor 中使用 DeepSeek-Coder
|
title: 如何在 Cursor 中使用 DeepSeek-Coder
|
||||||
publishDate: 2024-07-25
|
date: 2024-07-25
|
||||||
author: KazooTTT
|
author: KazooTTT
|
||||||
type: Post
|
type: Post
|
||||||
status: Draft
|
status: Draft
|
||||||
|
@ -13,12 +13,12 @@ interface Props {
|
|||||||
|
|
||||||
const { post } = Astro.props
|
const { post } = Astro.props
|
||||||
const {
|
const {
|
||||||
data: { description, ogImage, publishDate, title, updatedDate },
|
data: { description, ogImage, title, date },
|
||||||
slug
|
slug
|
||||||
} = post
|
} = post
|
||||||
|
|
||||||
const socialImage = ogImage ?? `/og-image/${slug}.png`
|
const socialImage = ogImage ?? `/og-image/${slug}.png`
|
||||||
const articleDate = updatedDate?.toISOString() ?? publishDate.toISOString()
|
const articleDate = date?.toISOString()
|
||||||
const { headings } = await post.render()
|
const { headings } = await post.render()
|
||||||
---
|
---
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ export const GET = async () => {
|
|||||||
items: posts.map((post) => ({
|
items: posts.map((post) => ({
|
||||||
title: post.data.title,
|
title: post.data.title,
|
||||||
description: post.data.description,
|
description: post.data.description,
|
||||||
pubDate: post.data.publishDate,
|
pubDate: post.data.date,
|
||||||
link: `/blog/${post.slug}`
|
link: `/blog/${post.slug}`
|
||||||
}))
|
}))
|
||||||
})
|
})
|
||||||
|
@ -10,8 +10,8 @@ export async function getAllPosts() {
|
|||||||
|
|
||||||
export function sortMDByDate(posts: Array<CollectionEntry<'post'>>) {
|
export function sortMDByDate(posts: Array<CollectionEntry<'post'>>) {
|
||||||
return posts.sort((a, b) => {
|
return posts.sort((a, b) => {
|
||||||
const aDate = new Date(a.data.updatedDate ?? a.data.publishDate).valueOf()
|
const aDate = new Date(a.data.date).valueOf()
|
||||||
const bDate = new Date(b.data.updatedDate ?? b.data.publishDate).valueOf()
|
const bDate = new Date(b.data.date).valueOf()
|
||||||
return bDate - aDate
|
return bDate - aDate
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -60,3 +60,10 @@ export function getUniqueCategoriesWithCount(
|
|||||||
)
|
)
|
||||||
].sort((a, b) => b[1] - a[1])
|
].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