fix(docs): check-doc-links 解析相对链接,并修掉它现在能看见的 16 个失效目标 (#3479) - #3489
Merged
Conversation
…targets it now catches (#3479) `routeExists()` opened with `if (!href.startsWith('/docs')) return true`, so every relative link was waved through unresolved. 33 references to 16 non-existent targets had accumulated behind it. Both halves land together, so the extended gate is green on arrival: - checker: relative hrefs are resolved against the linking file's directory, in the file form fumadocs' `source.resolveHref` keys on (extension included) plus the extensionless-route spellings. Absolute `/docs/...` stays route-only — `/docs/x.md` is a 404 on the site even when `x.md` exists on disk. Fenced and inline code is blanked first (two false positives on main otherwise). - content: 13 A-class links spelled `.md` where the file is `.mdx`; 3 B-class targets that do not exist (retargeted or removed, per-site reasons in the PR). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GTRjn8xBqp75dk7kFupVRt
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Collaborator
Author
|
补:正文末尾「顺手发现」那 18 条链接已单独开为 #3490(未指派、未打标签,交 PM 定级)。本 PR 不动它们 —— lychee 与扩展后的 checker 对这 18 条都判绿,因为两者只做「文件系统能否解析」,而它们的问题是「站点路由不存在」,与 #3479 的 16 个目标不是同一类失效。 Generated by Claude Code |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3479
两半一起落地:扩展后的门禁在本 PR 上是绿的(与 #3450 同一纪律 —— gate 到岸即绿,不带着自己描述的欠账进仓)。
前提复核:成立,但 issue 的归因要改一处 —— 这一改直接决定 A 类的正确修法
routeExists()确实以早退开场,相对链接从未被解析过:扩展后先在
origin/main的内容上跑,预期与实测完全吻合 issue 的口径:但 issue 写的原因「站上也是 404(fumadocs 路由无扩展名)」对相对链接不成立。站点对两种链接形态走的是两套机制:
apps/site/app/docs/[[...slug]]/page.tsx用 fumadocs 的createRelativeLink(source, page)渲染 MDX 的 a 标签;source.resolveHref(href, page),而该函数只处理.//../开头的 href —— 拼到dirname(page.path)上再查页面索引;createPageIndexer.scan()里pathToPage.set(path, page),path即filePath)。所以相对链接的正确形态是真实文件名(含真实扩展名),不是无扩展名路由。
../plugins/plugin-charts.mdx能被解析成真实路由;../plugins/plugin-charts.md查不到索引 → 原样落到浏览器 → 404(next.config.mjs只重写.mdx后缀,且重写到 llms 原始 markdown 路由)。实测(本 PR 的站点构建产物
apps/site/.next/server/app/docs/guide/plugins.html):../plugins/plugin-charts.mdx(本 PR 改后)/docs/plugins/plugin-charts✅./component-registry.md(仓库原有,文件确为.md)/docs/guide/component-registry✅../../../packages/data-objectstack/README.md#...(解析不了)../../../packages/...← A 类 404 的机制,反证A 类:规范判定 = 带扩展名的文件形态(
.mdx),统一应用除上面的机制证据外,既有链接的用法也一致:仓库原有 21 条相对链接全部写
./xxx.md且目标文件确实是.md—— 同一条规范,从未破过;而 297 条绝对/docs/...链接无一带扩展名 —— 因为绝对链接是路由,resolveHref根本不碰它。两种形态各有各的正确写法,checker 也因此分开校验。改动:13 个目标统一
.md→.mdx,共 27 处(guide/plugins.md26 处 +guide/record-edit-modes.md1 处)。B 类:先查 git history,逐条给理由
1.
guide/index.md:12[examples/server](examples/server)—— 整段删除examples/server/曾真实存在(5edecc5df加入),在88a098cf0"Remove example server files and configuration from the repository" 被删除。pnpm --filter @object-ui/example-objectstack-server serve连当年都是错的:那个包的真名是@object-ui/example-server(git show 88a098cf0^:examples/server/package.json)。## Examples标题和一条必然失败的命令。2.
guide/plugins.md:515[Lazy-Loaded Plugins Architecture](./lazy-loading.md)—— 删除该条docs/concepts/lazy-loading.md),在f22541271的docs/→content/docs/重排中被删,内容已并入本文件自己的### Lazy Loading Architecture(plugins.md:202,含React.lazy/Suspense示例与 13 个插件的 bundle 影响表)。3.
plugins/{charts,editor,kanban,markdown}.mdx的../concepts/lazy-loading(4 处)—— 改指/docs/guide/plugins#lazy-loading-architectureguide/plugins.md的该小节;这里是跨文档,深链到具体小节仍有信息量(同列表上一条只指到页面级/docs/guide/plugins)。/docs/guide/plugins保持一致。checker 扩展(
scripts/check-doc-links.mjs)dirname(源文件)解析,候选依次为「文件本身」(fumadocs 真正认的形态)+ 无扩展名路由形态(.md/.mdx/index.md/index.mdx)。无扩展名相对链接接受:它靠浏览器 URL 相对解析恰好落对,不是断链,门禁不该越权立风格规矩(脆弱性写在文件头注释里)。/docs/...href:保持路由形态严格 ——/docs/guide/b.md即便磁盘上有guide/b.md也判红,因为那个 URL 在站上就是 404。这是本 PR 特意没有放松的一处。/docs绝对 href(/spec/...、/api/...、/img/...)仍然放行:不在本 collection 内,从content/docs无从解析(见文末「顺手发现」)。main上现成两处:guide/notifications.md:54(tsx 围栏内的toast[n.severity](n.title, { description: n.message }))和fields/rich-text.mdx:47(行内代码里在讲语法本身)。剥离时用空格填充、保留换行,所以报出来的行号仍是真行号。stripCode/routeExists/collectBrokenLinks,invokedDirectly守卫沿用scripts/check-control-bytes.mjs的形状,便于测试直接调真函数。验证(方向先声明后运行)
origin/main内容Found 33 broken docs links (16 distinct targets),逐条与 issue 列表一致Docs links are valid./EXIT=0scripts/__tests__全量Test Files 11 passed (11) / Tests 166 passed (166)turbo run build --filter=@object-ui/site,CI 在content/**变更时会跑)✓ Compiled successfully in 86s/✓ Generating static pages (556/556)node scripts/check-control-bytes.mjsOK (scanned 3673 tracked text file(s))eslint改动文件反向验证:把删掉的
if (!cleanHref.startsWith(DOCS_ROUTE_PREFIX)) return true;那一肢装回去。事先预判:只有「期望报出断链」的用例转红;所有「期望空数组」的用例会照绿(一个全部放行的 checker 什么都不报),连带「仓库自身无断链」那条集成用例也照绿 —— 因为内容已经修好了,它压根挡不住这个回归。实测正是如此:这个不对称值得写下来:真正钉住这一肢的是那 6 条,「仓库自身绿」那条是内容的证据,不是 checker 的证据 —— 别把它当回归网。
无 changeset
按 AGENTS.md「纯 bug 修复不需要 changeset」:这是文档链接 + CI 脚本的修复,不改任何发布包的行为。
顺手发现(不在本 PR 修,另行开 issue)
扩展后的门禁仍有一处按设计的盲区,同一个根:它只在 docs collection 内解析。据此有 18 条链接在站上是 404 而门禁全绿 —— 1 条相对链接跑出了 collection(
guide/data-source.md:202),17 条非/docs绝对链接(/spec/*、/protocol/*、/api/core、/examples/*;apps/site/app下并无这些路由段,构建产物里它们原样输出)。Generated by Claude Code