diff options
Diffstat (limited to 'src/app/(main)/api')
| -rw-r--r-- | src/app/(main)/api/search/route.ts | 27 |
1 files changed, 18 insertions, 9 deletions
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); +} |
