chore: 去掉未上线前的旧兼容垫片,板块流收口到首页
鉴权只认 cookie、SEO 只走 Next、sort 与推荐对齐;删除 Bearer、Go sitemap、post_type 回填等冗余路径。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -5,7 +5,9 @@ import { PenSquare, SearchX, MessagesSquare } from "lucide-react";
|
||||
import {
|
||||
fetchPosts,
|
||||
fetchOverview,
|
||||
fetchBoardSidebar,
|
||||
type OverviewResponse,
|
||||
type BoardSidebarResponse,
|
||||
} from "@/lib/api";
|
||||
import { authCookieHeader } from "@/lib/cookies";
|
||||
import { getMeCached } from "@/lib/serverData";
|
||||
@@ -15,6 +17,11 @@ import FeedTabs, { type FeedSort } from "@/components/home/FeedTabs";
|
||||
import FeedNewTip from "@/components/home/FeedNewTip";
|
||||
import { WorkspaceNav, WorkspaceNavMobile } from "@/components/home/WorkspaceNav";
|
||||
import { CommunityPanels, CommunityPanelsMobile } from "@/components/home/CommunityPanels";
|
||||
import {
|
||||
BoardPanels,
|
||||
BoardPanelsMobile,
|
||||
BoardMissingPanel,
|
||||
} from "@/components/home/BoardPanels";
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "姜十三论坛 · 技术讨论社区",
|
||||
@@ -27,8 +34,6 @@ interface HomePageProps {
|
||||
|
||||
function normalizeSort(v?: string): FeedSort {
|
||||
if (v === "new" || v === "recommended") return v;
|
||||
// 兼容旧的 ?sort=hot 链接:落到最接近的推荐帖
|
||||
if (v === "hot") return "recommended";
|
||||
return "latest";
|
||||
}
|
||||
|
||||
@@ -81,22 +86,30 @@ export default async function HomePage({ searchParams }: HomePageProps) {
|
||||
page,
|
||||
20,
|
||||
isSearch || boardId <= 0 ? undefined : boardId,
|
||||
sort === "recommended" ? "hot" : sort,
|
||||
sort,
|
||||
keyword,
|
||||
sort === "recommended",
|
||||
cookie
|
||||
);
|
||||
// 聚合面板失败不阻塞帖子流
|
||||
const overviewPromise: Promise<OverviewResponse | null> = fetchOverview(cookie).catch(() => null);
|
||||
const boardSidebarPromise: Promise<BoardSidebarResponse | null> =
|
||||
boardId > 0 && !isSearch
|
||||
? fetchBoardSidebar(boardId, cookie).catch(() => null)
|
||||
: Promise.resolve(null);
|
||||
|
||||
const [me, postsData, overview] = await Promise.all([
|
||||
const [me, postsData, overview, boardSidebar] = await Promise.all([
|
||||
mePromise,
|
||||
postsPromise,
|
||||
overviewPromise,
|
||||
boardSidebarPromise,
|
||||
]);
|
||||
const user = me.user;
|
||||
const boards = overview?.boards ?? [];
|
||||
const activeBoard = boards.find((b) => b.id === boardId) || null;
|
||||
const activeBoard = boards.find((b) => b.id === boardId) || boardSidebar?.board || null;
|
||||
const showBoardPanels = boardId > 0 && !isSearch;
|
||||
// boardId 有效但接口失败 → 显示简卡;成功则板级右栏;否则全站右栏
|
||||
const boardPanelsMissing = showBoardPanels && !boardSidebar;
|
||||
|
||||
// 搜索态:单栏占满,无 Tabs/侧栏
|
||||
if (isSearch) {
|
||||
@@ -193,31 +206,61 @@ export default async function HomePage({ searchParams }: HomePageProps) {
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* 右栏:社区面板 */}
|
||||
{overview && (
|
||||
<CommunityPanels
|
||||
stats={overview.stats}
|
||||
hot={overview.hot}
|
||||
activeUsers={overview.active_users}
|
||||
announcements={overview.announcements}
|
||||
newUsers={overview.new_users}
|
||||
checkin={overview.checkin ?? undefined}
|
||||
/>
|
||||
{/* 右栏:选中板块时切板级面板,否则全站社区面板 */}
|
||||
{showBoardPanels ? (
|
||||
boardSidebar ? (
|
||||
<BoardPanels
|
||||
board={boardSidebar.board}
|
||||
moderators={boardSidebar.moderators}
|
||||
stats={boardSidebar.stats}
|
||||
hot={boardSidebar.hot}
|
||||
activeUsers={boardSidebar.active_users}
|
||||
checkin={boardSidebar.checkin ?? undefined}
|
||||
/>
|
||||
) : boardPanelsMissing ? (
|
||||
<BoardMissingPanel />
|
||||
) : null
|
||||
) : (
|
||||
overview && (
|
||||
<CommunityPanels
|
||||
stats={overview.stats}
|
||||
hot={overview.hot}
|
||||
activeUsers={overview.active_users}
|
||||
announcements={overview.announcements}
|
||||
newUsers={overview.new_users}
|
||||
checkin={overview.checkin ?? undefined}
|
||||
/>
|
||||
)
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* 窄屏:面板下沉到帖子流之后 */}
|
||||
{overview && (
|
||||
<div className="mt-6">
|
||||
<CommunityPanelsMobile
|
||||
stats={overview.stats}
|
||||
hot={overview.hot}
|
||||
activeUsers={overview.active_users}
|
||||
announcements={overview.announcements}
|
||||
newUsers={overview.new_users}
|
||||
checkin={overview.checkin ?? undefined}
|
||||
/>
|
||||
</div>
|
||||
{showBoardPanels ? (
|
||||
boardSidebar ? (
|
||||
<div className="mt-6">
|
||||
<BoardPanelsMobile
|
||||
board={boardSidebar.board}
|
||||
moderators={boardSidebar.moderators}
|
||||
stats={boardSidebar.stats}
|
||||
hot={boardSidebar.hot}
|
||||
activeUsers={boardSidebar.active_users}
|
||||
checkin={boardSidebar.checkin ?? undefined}
|
||||
/>
|
||||
</div>
|
||||
) : null
|
||||
) : (
|
||||
overview && (
|
||||
<div className="mt-6">
|
||||
<CommunityPanelsMobile
|
||||
stats={overview.stats}
|
||||
hot={overview.hot}
|
||||
activeUsers={overview.active_users}
|
||||
announcements={overview.announcements}
|
||||
newUsers={overview.new_users}
|
||||
checkin={overview.checkin ?? undefined}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user