diff --git a/src/components/ArchivePanel.svelte b/src/components/ArchivePanel.svelte index ef76926..39174a6 100644 --- a/src/components/ArchivePanel.svelte +++ b/src/components/ArchivePanel.svelte @@ -21,6 +21,7 @@ interface Post { tags: string[]; category?: string | null; published: Date; + pinned?: boolean; }; } @@ -131,9 +132,14 @@ onMount(async () => {
- {post.data.title} + {#if post.data.pinned} + + 置顶 + + {/if} + {post.data.title}
diff --git a/src/components/PostCard.astro b/src/components/PostCard.astro index 6116c3e..ac153d6 100644 --- a/src/components/PostCard.astro +++ b/src/components/PostCard.astro @@ -40,6 +40,7 @@ const className = Astro.props.class; const hasCover = image !== undefined && image !== null && image !== ""; const coverWidth = "28%"; +const isPinned = entry.data.pinned; const isOutdated = entry.data.outdated; const { remarkPluginFrontmatter } = await render(entry); @@ -53,9 +54,21 @@ const { remarkPluginFrontmatter } = await render(entry); before:w-1 before:h-5 before:rounded-md before:bg-[var(--primary)] before:absolute before:top-[35px] before:left-[18px] before:hidden md:before:block "> - {title} - - + + {isPinned && ( + + + 置顶 + + )} + + {title} + + + + + + diff --git a/src/content.config.ts b/src/content.config.ts index 2068e18..9f50203 100644 --- a/src/content.config.ts +++ b/src/content.config.ts @@ -15,6 +15,7 @@ const postsCollection = defineCollection({ category: z.string().optional().nullable().default(""), showcover: z.boolean().optional().default(true), customcover: z.string().optional().default(""), + pinned: z.boolean().optional().default(false), outdated: z.boolean().optional().default(false), lang: z.string().optional().default(""), prevTitle: z.string().default(""), diff --git a/src/content/posts/new-domain.md b/src/content/posts/new-domain.md index 5623498..30ccdf6 100644 --- a/src/content/posts/new-domain.md +++ b/src/content/posts/new-domain.md @@ -1,6 +1,7 @@ --- -title: "[置顶] 新域名!" -published: 2099-12-31 +title: "新域名!" +published: 2025-08-06 +pinned: true tags: ["域名"] description: 获得了一个新域名 *这使我充满了决心 image: /public/pic/domain-inlist-adclosenn.top.png diff --git a/src/types/config.ts b/src/types/config.ts index c8c474b..0c6ee16 100644 --- a/src/types/config.ts +++ b/src/types/config.ts @@ -101,6 +101,7 @@ export type BlogPostData = { draft?: boolean; image?: string; category?: string; + pinned?: boolean; prevTitle?: string; prevSlug?: string; nextTitle?: string; diff --git a/src/utils/content-utils.ts b/src/utils/content-utils.ts index c7b4fa9..bd09f79 100644 --- a/src/utils/content-utils.ts +++ b/src/utils/content-utils.ts @@ -10,6 +10,10 @@ async function getRawSortedPosts() { }); const sorted = allBlogPosts.sort((a, b) => { + if (a.data.pinned !== b.data.pinned) { + return a.data.pinned ? -1 : 1; + } + const dateA = new Date(a.data.published); const dateB = new Date(b.data.published); return dateA > dateB ? -1 : 1;