Repository navigation
fix(llm-md): 文档 Markdown 版补页面标题,展开 SDKLinks 和 QuotePermission - #1345
Merged
twosugar merged 1 commit intoNov 24, 2026
Merged
Conversation
…docs .md export
The /docs/<path>.md routes (listed in llms.txt for AI readers) returned the raw
mdx body: no page title, and <SDKLinks> / <QuotePermission> left as bare tags.
- New src/lib/markdown-export.ts used by both .md routes (en + zh-CN/zh-HK):
- prepend `# <frontmatter title>` when the body (outside code fences and
<CliCommand> blocks) has no H1
- expand <SDKLinks> into the SDK method name plus per-language SDK reference
links; URL rules extracted to packages/ui/src/sdk-links.ts and shared with
the web component
- replace <QuotePermission> with the quote-permission callout from
quote-permissions.yaml (same text as the web component and the API
Reference .md)
- component examples inside code fences / inline code are left untouched
- Tests: src/lib/markdown-export.test.ts
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
背景
文档页的 Markdown 版(
/docs/<path>.md,llms.txt 列出来给 AI 读的那份)现在直接返回 mdx 正文,有两个问题:title里,正文从说明句开始。例如 https://open.longbridge.com/docs/fundamental/fundamental/dividends.md 第一行是「Get dividend history and upcoming dividend announcements for a security.」,AI 读到时不知道这是哪个接口。<SDKLinks module="fundamental" klass="FundamentalContext" method="dividends" />、<QuotePermission command="brokers" />原样输出,AI 拿不到对应的 SDK 方法和各语言文档链接,也看不到这个接口要什么行情权限。改动
src/lib/markdown-export.ts,src/pages/[...slug].md.ts(英文)和src/pages/[locale]/[...slug].md.ts(简体、繁体)的GET都改调它:<CliCommand>块后没有一级标题时,开头补# <frontmatter title>。<CliCommand>里的# 注释不算标题。<SDKLinks … />展开成小标题(和网页一致,默认「SDK Links」,:title="false"时不出)、一行「SDK method:dividends」(中文页为「SDK 方法:」)和 Python、Rust、Go、Node.js、Java、C++ 六个参考文档链接(hideGo时去掉 Go)。<QuotePermission … />换成所需行情权限说明(标题 · 市场 · 等级、说明、「OpenAPI 行情权限独立于 App/Web 行情权限」),按页面语言取quote-permissions.yaml的文案,和网页组件同一份数据。<CliCommand>、:::提示块不处理。packages/ui/src/SDKLinks.tsx里拼网址的部分(含 C++ 锚点表、Java 方法表)抽到packages/ui/src/sdk-links.ts的resolveSdkLinks,网页组件和 Markdown 版共用,网页输出不变。packages/api-reference/src/openapi-markdown.ts原有的quotePermissionMarkdown拆出可导出的quotePermissionCallout,接口参考页的.md和文档页的.md共用,接口参考页输出不变。src/lib/markdown-export.test.ts(7 条):缺标题补标题、已有标题不重复、SDKLinks 展开、:title="false"和hideGo、QuotePermission 英文和繁体、代码块里的示例不动、属性解析。验证
按仓库 CLAUDE.md 没有在 AI 会话里跑
build:*,改用新函数对 docs 下全部源文件逐个算(和.md路由同样的范围:去掉接口参考/docs/api和首页):<SDKLinks(改前 → 改后)<QuotePermission(改前 → 改后)(标签数只算代码块和行内代码以外的。之前按「
#开头的行」粗算英文缺标题是 149 篇,那个算法把<CliCommand>里的# 注释也当成了标题;去掉命令行块后实际是 197。)另有 3 组页面(
cli/account/dca、cli/market-data/broker-holding、skill/install,三语各 1)本来就有一级标题,只是前面先有提示块或注释,这次不动。bun run test:12 个文件 106 条全部通过。oxlint:通过。astro sync、astro check:0 errors、0 warnings。tsc --noEmit:只剩主干原有的McpToolsIsland.astro模块声明那一条,本次没有新增。.md文本输出;网页上的 SDKLinks 只是把拼网址的代码挪到共用函数,输出不变,没有新增接口请求,页面体积不变。改后样例(英文 dividends.md 开头):
broker.md 里的行情权限:
上线后验证
用监控标识
Mozilla/5.0 (compatible; LongbridgeSEOMonitor/1.0; +https://longbridge.com/robots.txt)取下面的网址(加随机参数绕缓存):期望:第一行以
#开头,全文不含<SDKLinks、<QuotePermission。顺带发现(本 PR 没改)
docs/*/docs/trade/trade-push.mdx里的<SDKLinks :title="false" … />经过astro.config.ts预处理第 6 步变成字符串title="false",网页上出了一个文字为「false」的二级标题(线上 https://open.longbridge.com/docs/trade/trade-push 可见<h2>false</h2>)。要修的话可以在文档里改成title={false},或在组件里把字符串"false"当成不显示,麻烦看要不要另开一个处理。麻烦有空时帮忙看一下,谢谢!
🤖 Generated with Claude Code