链接与导航
页面间链接、特定标题锚点及外部 URL 引用。包含卡片导航与失效链接检查。
MDX 支持标准 Markdown 链接。Jamdesk 另外提供页面链接、标题锚点和外部 URL 的写法。
内部链接
使用相对路径链接到文档中的其他页面:
Read the [getting started guide](/quickstart) first.
See the [Card component](/components/card) for more options.
路径相对于文档根目录书写,无需 .mdx 扩展名。
链接到标题
使用锚点链接直接跳转到某个章节:
See [configuration options](/config/docs-json-reference#colors)
标题会根据其文本自动生成锚点:
## Getting Started→#getting-started## API Reference→#api-reference
外部链接
链接到外部网站:
Check the [GitHub repository](https://github.com/example/repo).
外部链接会以安全设置在新标签页中打开。
使用 Card 创建链接
如需突出显示的导航,可使用卡片代替行内链接:
<Card title="Quickstart" icon="rocket" href="/quickstart">
Get up and running in 5 minutes
</Card>
Card 组
将相关链接组合在一起:
<Columns cols={2}>
<Card title="Installation" icon="download" href="/cli/overview">
Install the CLI
</Card>
<Card title="Configuration" icon="gear" href="/config/docs-json-reference">
Configure your project
</Card>
</Columns>
最佳实践
告诉读者链接指向何处:
{/* Good */}
Learn more in our [authentication guide](/quickstart).
{/* Avoid */}
For more info, [click here](/quickstart).链接到最具体的相关章节:
{/* Good - links to specific section */}
Configure [OAuth settings](/quickstart#whats-next).
{/* Less helpful - links to entire page */}
See the [auth docs](/quickstart) for OAuth settings.失效链接会影响读者体验。请定期运行链接检查:
jamdesk broken-links此命令会扫描文档并报告所有失效的内部链接。
检查断开的链接
Jamdesk CLI 可以扫描失效链接:
jamdesk broken-links
示例输出:
docs/getting-started.mdx:15 - /docs/quikstart
Did you mean: /docs/quickstart
Found 1 broken link in 45 files.
部署前运行此命令,以发现拼写错误和过时的引用。
自动修复断开的链接
jamdesk fix 可修复那些只有唯一正确目标的失效链接(例如拼写错误的锚点,或译文页面重命名标题后导致的跨语言锚点偏移):
jamdesk fix --dry-run # preview every planned fix, write nothing
jamdesk fix # apply after a y/N confirmation
只有当修正后的锚点确实是目标页面上的标题时,它才会改写链接。存在歧义的情况会留给人工审阅。参见 自动修复失效链接。
如何检测内部链接
不以 https:// 开头的链接被视为内部链接,并会对照你的文档页面进行验证。验证器会检查目标页面是否存在于 docs.json 导航中。
使用 hostAtDocs(文档托管在子路径如 /docs 下)的站点,会在运行时为内部链接自动添加 /docs 前缀。请使用相对于文档根目录的路径书写:
{/* Just write the docs path — auto-prefixed to /docs/config/docs-json-reference */}
See the [Reference](/config/docs-json-reference).
非文档链接(如营销页面)应使用完整 URL:https://example.com/pricing。
文档内容中任何 /path 形式的链接都会被视为内部文档链接。
重命名页面
重命名页面会使指向它的链接失效。请使用 CLI 更新所有引用:
jamdesk rename api/old-name.mdx api/new-name.mdx
此命令会:
- 重命名文件
- 更新
docs.json导航 - 修复其他所有页面中的链接
