feat(posts): 类型特殊块移至正文下,采纳答案卡与中奖楼层按评论标记

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-09-16 08:33:00 +08:00
parent 92695c2143
commit 44fdcace4c
8 changed files with 410 additions and 83 deletions

View File

@@ -35,7 +35,8 @@ import RoleBadge from "@/components/RoleBadge";
import MarkdownBody from "@/components/MarkdownBody";
import ContentLockGate from "@/components/ContentLockGate";
import PostAttachments from "@/components/PostAttachments";
import PostInteractPanels from "@/components/PostInteractPanels";
import PostInteractPanels, { QuestionStatusCard } from "@/components/PostInteractPanels";
import AcceptedAnswerCard from "@/components/AcceptedAnswerCard";
import { canModerateBoard } from "@/lib/roles";
import { IconComment, IconEye } from "@/components/Icons";
import { normalizePostType, postTypeLabel, contentAccessLabel, typeStatusLabel, typeStatusClass } from "@/lib/postMeta";
@@ -479,6 +480,24 @@ export default async function PostDetailPage({ params, searchParams }: PageProps
? ("bounty" as const)
: null;
const acceptedAnswer =
post.question?.accepted_answer || post.bounty?.accepted_answer || null;
const acceptedAnswerVariant =
postType === "bounty" && post.bounty?.accepted_answer
? ("bounty" as const)
: ("question" as const);
const questionState =
postType === "question"
? post.question ?? {
solved: false,
accepted_comment_id: 0,
accepted_floor: 0,
can_accept: canManageTyped,
can_solve: canManageTyped,
can_reopen: false,
}
: null;
const jsonLd = {
"@context": "https://schema.org",
"@type": "DiscussionForumPosting",
@@ -494,6 +513,20 @@ export default async function PostDetailPage({ params, searchParams }: PageProps
interactionType: { "@type": "ReadAction" },
userInteractionCount: post.view_count,
},
...(acceptedAnswer &&
!acceptedAnswer.deleted &&
!post.content_locked && {
acceptedAnswer: {
"@type": "Comment",
text: acceptedAnswer.content,
dateCreated: acceptedAnswer.created_at,
author: {
"@type": "Person",
name: acceptedAnswer.user.nickname || acceptedAnswer.user.username,
},
url: `#comment-${acceptedAnswer.id}`,
},
}),
};
// 目录项与 Markdown 标题按渲染顺序一一对应(extractToc 顺序 == 文档顺序)
@@ -650,26 +683,6 @@ export default async function PostDetailPage({ params, searchParams }: PageProps
</div>
)}
<PostInteractPanels
postId={post.id}
question={
postType === "question"
? post.question ?? {
solved: false,
accepted_comment_id: 0,
accepted_floor: 0,
can_accept: canManageTyped,
can_solve: canManageTyped,
can_reopen: false,
}
: post.question
}
poll={post.poll}
bounty={post.bounty}
lottery={post.lottery}
loggedIn={!!me.user}
/>
{post.content_locked ? (
<ContentLockGate
postId={post.id}
@@ -689,6 +702,25 @@ export default async function PostDetailPage({ params, searchParams }: PageProps
<PostAttachments postId={post.id} items={post.attachments || []} />
)}
{/* 类型特殊块(投票/悬赏/抽奖/问答)统一放正文最下方 */}
<PostInteractPanels
postId={post.id}
poll={post.poll}
bounty={post.bounty}
lottery={post.lottery}
loggedIn={!!me.user}
/>
{!post.content_locked && acceptedAnswer ? (
<AcceptedAnswerCard
answer={acceptedAnswer}
variant={acceptedAnswerVariant}
postId={post.id}
canReopen={!!post.question?.can_reopen}
/>
) : questionState ? (
<QuestionStatusCard postId={post.id} state={questionState} />
) : null}
{/* 文末点赞:分隔线后居中,唯一的点赞入口(作者行不再放置) */}
<div
className="mt-9 pt-7 flex justify-center"
@@ -729,9 +761,11 @@ export default async function PostDetailPage({ params, searchParams }: PageProps
post.bounty?.accepted_comment_id ||
0
}
winnerUserIds={
winnerCommentIds={
post.lottery?.drawn
? (post.lottery.winners || []).map((w) => w.id)
? (post.lottery.winners || [])
.map((w) => w.comment_id || 0)
.filter((id) => id > 0)
: []
}
/>