Skip to content

Commit 8044e39

Browse files
longsizhuogithub-actions[bot]
authored andcommitted
fix(search): 改用 fumadocs-core/mdx-plugins 公开导出的 StructuredData,删本地副本
上一版在 lib/search-index.ts 维护了 PageStructuredData 本地副本,理由是 fumadocs-core 的 StructuredData "没 export"。复查 node_modules 发现 fumadocs-core@15.7.13 的 dist/mdx-plugins/index.d.ts 有: export { ..., S as StructuredData, ... } from '../remark-structure-...'; package.json 里 './mdx-plugins' 也是公开 exports 入口,就是典型的公开 API。 直接 import 上游类型,删掉本地 PageStructuredData,消除跟 fumadocs 升级 drift 的风险。 PageDataShape 内部字段全部换成上游 StructuredData,和 AdvancedIndex.structuredData 结构一致。
1 parent acb3d7a commit 8044e39

1 file changed

Lines changed: 6 additions & 13 deletions

File tree

lib/search-index.ts

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,19 @@
11
import type { AdvancedIndex } from "fumadocs-core/search/server";
2+
// StructuredData 是 fumadocs-core 的公开导出(从 mdx-plugins 入口),
3+
// 直接用上游类型,不再在本地维护同形副本以免两边 drift。
4+
import type { StructuredData } from "fumadocs-core/mdx-plugins";
25
import { source } from "@/lib/source";
36
import { basename, extname } from "path";
47

58
type Page = ReturnType<typeof source.getPages>[number];
69

7-
/**
8-
* fumadocs 页面 data 里可能携带的结构化搜索数据。
9-
* 形状与 fumadocs-core 的 StructuredData 对齐(headings + contents),
10-
* 但我们从 page.data 运行时读出来,所以显式写成本地类型别名,不依赖内部导出。
11-
*/
12-
interface PageStructuredData {
13-
headings: { id: string; content: string }[];
14-
contents: { heading: string | undefined; content: string }[];
15-
}
16-
1710
/**
1811
* fumadocs page.data 在构建产物里的 runtime shape。
1912
* 老路径:structuredData 直接 inline;新路径:通过 load() 异步拉。
2013
*/
2114
interface PageDataShape {
22-
structuredData?: PageStructuredData;
23-
load?: () => Promise<{ structuredData: PageStructuredData }>;
15+
structuredData?: StructuredData;
16+
load?: () => Promise<{ structuredData: StructuredData }>;
2417
title?: string;
2518
description?: string;
2619
}
@@ -32,7 +25,7 @@ interface PageDataShape {
3225
export async function pageToIndex(page: Page): Promise<AdvancedIndex> {
3326
const data = page.data as PageDataShape;
3427

35-
let structuredData: PageStructuredData | undefined;
28+
let structuredData: StructuredData | undefined;
3629
if (data.structuredData) {
3730
structuredData = data.structuredData;
3831
} else if (typeof data.load === "function") {

0 commit comments

Comments
 (0)