Skip to content

fix(llm-md): 文档 Markdown 版补页面标题,展开 SDKLinks 和 QuotePermission - #1345

Merged
twosugar merged 1 commit into
longbridge:mainfrom
nic75408:fix/md-export-title-components
Nov 24, 2026
Merged

twosugar merged 1 commit into
longbridge:mainfrom
nic75408:fix/md-export-title-components

Conversation

@nic75408

Copy link
Copy Markdown
Contributor

背景

文档页的 Markdown 版(/docs/<path>.md,llms.txt 列出来给 AI 读的那份)现在直接返回 mdx 正文,有两个问题:

  1. 没有页面标题。 很多文档的标题只写在 frontmatter title 里,正文从说明句开始。例如 https://open.longbridge.com/docs/fundamental/fundamental/dividends.md 第一行是「Get dividend history and upcoming dividend announcements for a security.」,AI 读到时不知道这是哪个接口。
  2. 组件只剩原样标签。 <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(改前 → 改后)
英文 311 197 → 0 166 → 0 62 → 0
简体 305 197 → 0 166 → 0 62 → 0
繁体 305 199 → 0 166 → 0 62 → 0

(标签数只算代码块和行内代码以外的。之前按「# 开头的行」粗算英文缺标题是 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 开头):

# Dividends

Get dividend history and upcoming dividend announcements for a security.

<CliCommand>
longbridge dividend TSLA.US
longbridge dividend AAPL.US
</CliCommand>

## SDK Links

SDK method: `dividends`

- Python: [longbridge.openapi.FundamentalContext.dividends](https://longbridge.github.io/openapi/python/reference_all/#longbridge.openapi.FundamentalContext.dividends)
- Rust: [longbridge::fundamental::FundamentalContext#dividends](https://longbridge.github.io/openapi/rust/longbridge/fundamental/struct.FundamentalContext.html#method.dividends)
…

broker.md 里的行情权限:

> **Quote Permission Required · HK only · LV2 Advanced**
> HK-specific data: provides the top 40 bid/ask broker queues.
> No permission included by default — purchase "LV2 Advanced Quotes - Plus (OpenAPI)" in the Quote Store.
> _OpenAPI quote perms are separate from App/Web perms_

上线后验证

用监控标识 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

…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>
@twosugar
twosugar merged commit c3a7884 into longbridge:main Nov 24, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants