@@ -0,0 +1,48 @@
|
||||
import type { Metadata } from "next";
|
||||
import { redirect } from "next/navigation";
|
||||
import { Suspense } from "react";
|
||||
|
||||
import { PageLoading } from "@/components/common/page-loading";
|
||||
import { buildSearchList, parseSearchType } from "@/components/search/data";
|
||||
import { searchListHref } from "@/components/search/route";
|
||||
import { SearchPage } from "@/components/search/search-page";
|
||||
import { resolvePageMetadata } from "@/lib/seo";
|
||||
|
||||
type SearchParams = Promise<{ q?: string | string[]; type?: string | string[]; page?: string | string[] }>;
|
||||
|
||||
function first(value: string | string[] | undefined) {
|
||||
return Array.isArray(value) ? value[0] : value;
|
||||
}
|
||||
|
||||
export async function generateMetadata(): Promise<Metadata> {
|
||||
return resolvePageMetadata({
|
||||
fallbackTitle: "搜索",
|
||||
fallbackDescription: "搜索海角社区短剧与视频。",
|
||||
fallbackKeywords: ["海角社区", "搜索"],
|
||||
canonical: "/search",
|
||||
// 搜索入口不收录;robots.txt 同步 Disallow /search
|
||||
robots: { index: false, follow: false },
|
||||
});
|
||||
}
|
||||
|
||||
/** 兼容旧链接 /search?q=&type=&page= → /search/{type}/{q}[/{page}] */
|
||||
async function SearchIndexContent({ searchParams }: { searchParams: SearchParams }) {
|
||||
const params = await searchParams;
|
||||
const query = first(params.q)?.trim() ?? "";
|
||||
const type = parseSearchType(first(params.type));
|
||||
const page = Number(first(params.page)) || 1;
|
||||
|
||||
if (query) {
|
||||
redirect(searchListHref(query, type, page > 1 ? page : 1));
|
||||
}
|
||||
|
||||
return <SearchPage list={buildSearchList(null, "", type, 1)} />;
|
||||
}
|
||||
|
||||
export default function Page({ searchParams }: { searchParams: SearchParams }) {
|
||||
return (
|
||||
<Suspense fallback={<PageLoading />}>
|
||||
<SearchIndexContent searchParams={searchParams} />
|
||||
</Suspense>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user