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/app/(main)/api/search/route.ts | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'src/app/(main)/api/search/route.ts') diff --git a/src/app/(main)/api/search/route.ts b/src/app/(main)/api/search/route.ts index 3c99f5c..cc2a1c8 100644 --- a/src/app/(main)/api/search/route.ts +++ b/src/app/(main)/api/search/route.ts @@ -1,11 +1,20 @@ -import { getPosts } from '@/lib/source'; +import { getPublishedPosts } from '@/lib/payload-posts'; import { createSearchAPI } from 'fumadocs-core/search/server'; -export const { GET } = createSearchAPI('advanced', { - indexes: getPosts().map((page) => ({ - title: page.data.title, - structuredData: page.data.structuredData, - id: page.url, - url: page.url, - })), -}); +// 动态生成搜索索引 +export async function GET(request: Request) { + const { posts } = await getPublishedPosts({ limit: 1000 }); + + const indexes = posts.map((post) => ({ + title: post.title, + description: post.description, + id: post.url, + url: post.url, + })); + + const searchAPI = createSearchAPI('advanced', { + indexes, + }); + + return searchAPI.GET(request); +} -- cgit v1.2.3