From 785371bb3eccca455e5ce5fccbe9b6e3752a03f6 Mon Sep 17 00:00:00 2001 From: Bertrand Yuan Date: Tue, 16 Dec 2025 00:15:04 +0800 Subject: fix(front-end): bug in viewing posts --- src/components/json-ld.tsx | 29 +++++++++++++---------------- src/components/sections/footer.tsx | 30 ++++++++++-------------------- src/components/tags/tag-card.tsx | 9 ++++----- 3 files changed, 27 insertions(+), 41 deletions(-) (limited to 'src/components') diff --git a/src/components/json-ld.tsx b/src/components/json-ld.tsx index a7cd884..58cb0ba 100644 --- a/src/components/json-ld.tsx +++ b/src/components/json-ld.tsx @@ -1,33 +1,30 @@ import { title as homeTitle } from '@/app/(main)/layout.config'; import { owner } from '@/app/(main)/layout.config'; import { baseUrl } from '@/lib/constants'; -import type { Post } from '@/lib/source'; +import type { BlogPost } from '@/lib/payload-posts'; import type { BlogPosting, BreadcrumbList, Graph } from 'schema-dts'; -export const PostJsonLd = ({ page }: { page: Post }) => { - if (!page) { +export const PostJsonLd = ({ post }: { post: BlogPost }) => { + if (!post) { return null; } - const url = new URL(page.url, baseUrl.href).href; + const url = new URL(post.url, baseUrl.href).href; - const post: BlogPosting = { + const blogPosting: BlogPosting = { '@type': 'BlogPosting', - headline: page.data.title, - description: page.data.description, - image: new URL(`/og/${page.slugs.join('/')}/image.png`, baseUrl.href).href, - datePublished: new Date(page.data.date).toISOString(), - dateModified: page.data.lastModified - ? new Date(page.data.lastModified).toISOString() - : undefined, + headline: post.title, + description: post.description, + image: post.image ? new URL(post.image, baseUrl.href).href : undefined, + datePublished: post.date.toISOString(), + dateModified: post.updatedAt.toISOString(), mainEntityOfPage: { '@type': 'WebPage', '@id': url, }, author: { '@type': 'Person', - name: page.data.author, - // url: 'https://techwithanirudh.com/', + name: post.author, }, publisher: { '@type': 'Person', @@ -54,7 +51,7 @@ export const PostJsonLd = ({ page }: { page: Post }) => { { '@type': 'ListItem', position: 3, - name: page.data.title, + name: post.title, item: url, }, ], @@ -62,7 +59,7 @@ export const PostJsonLd = ({ page }: { page: Post }) => { const graph: Graph = { '@context': 'https://schema.org', - '@graph': [post, breadcrumbList], + '@graph': [blogPosting, breadcrumbList], }; return ( diff --git a/src/components/sections/footer.tsx b/src/components/sections/footer.tsx index 3a1b51d..a982810 100644 --- a/src/components/sections/footer.tsx +++ b/src/components/sections/footer.tsx @@ -1,18 +1,19 @@ import { baseOptions, linkItems, postsPerPage } from '@/app/(main)/layout.config'; import { InlineLink } from '@/components/inline-link'; -import { getSortedByDatePosts, getTags } from '@/lib/source'; +import { getPublishedPosts, getAllTags } from '@/lib/payload-posts'; import { cn } from '@/lib/utils'; import { getLinks } from 'fumadocs-ui/layouts/shared'; import { ActiveLink } from '../active-link'; -export function Footer() { +export async function Footer() { const links = getLinks(linkItems, baseOptions.githubUrl); const navItems = links.filter((item) => ['nav', 'all'].includes(item.on ?? 'all'), ); - const posts = getSortedByDatePosts(); - const tags = getTags(); + // 从 Payload 获取文章和标签 + const { posts } = await getPublishedPosts({ limit: postsPerPage }); + const tags = await getAllTags(); return ( ); } - -function Design() { - return ( -
- john•doe -
-
-
- ); -} diff --git a/src/components/tags/tag-card.tsx b/src/components/tags/tag-card.tsx index a71e4c4..447c73e 100644 --- a/src/components/tags/tag-card.tsx +++ b/src/components/tags/tag-card.tsx @@ -1,19 +1,18 @@ import { Icons } from '@/components/icons/icons'; -import { getPostsByTag } from '@/lib/source'; import { cn } from '@/lib/utils'; import Link from 'next/link'; export const TagCard = ({ name, displayCount = false, + count, className = '', }: { name: string; displayCount?: boolean; + count?: number; className?: string; }) => { - const posts = getPostsByTag(name); - return ( {name} - {displayCount && ( - ({posts.length}) + {displayCount && count !== undefined && ( + ({count}) )} ); -- cgit v1.2.3