关于插件
astro-smart-links 是一个用于增强 Markdown 文档中链接的 rehype 插件。它通过添加智能导航和样式功能,帮助用户区分不同类型的链接,提升文档阅读体验。
1. 智能链接分类
Section titled “1. 智能链接分类”插件会自动检测和分类链接为以下三种类型:
- 内部链接 - 指向网站内部页面的链接
- 外部链接 - 指向其他网站的链接
- 断开链接 - 指向不存在页面的链接
2. 类名和属性添加
Section titled “2. 类名和属性添加”插件为不同类型的链接添加特定的类名和属性:
<!-- 内部链接 --><a href="/about" class="internal-link">关于页面</a>
<!-- 外部链接 --><a href="https://example.com" class="external-link" target="_blank" rel="noopener noreferrer">示例网站</a>
<!-- 断开链接 --><a href="/non-existent" class="broken-link">不存在的页面</a>3. 自定义配置
Section titled “3. 自定义配置”插件提供丰富的自定义配置选项,让你能够根据自己的需求调整链接处理行为:
| 选项 | 类型 | 默认值 | 描述 |
|---|---|---|---|
internalLinkClass |
string |
'internal-link' |
内部链接的类名 |
externalLinkClass |
string |
'external-link' |
外部链接的类名 |
brokenLinkClass |
string |
'broken-link' |
断开链接的类名 |
target |
string |
'_blank' |
外部链接的 target 属性 |
rel |
string |
'noopener noreferrer' |
外部链接的 rel 属性 |
ignore |
(string | RegExp)[] |
[] |
不参与处理的链接 |
content |
object | null |
{ type: 'text', value: '↗' } |
外部链接追加的图标内容 |
routes / routesFile / publicDir |
— | — | 断链检测的路由来源(使用集成时自动获取) |
failOnBroken |
boolean |
false |
发现断链时中止构建(集成选项) |
astro-smart-links 适用于各种使用 Markdown 的项目:
- 文档网站 - 提升文档导航体验
- 博客平台 - 增强博客文章中的链接
- 知识库 - 改善知识库内容的链接可用性
查看我们的 快速上手 指南,了解如何在你的项目中使用 astro-smart-links。
我们欢迎社区贡献!如果你有任何问题或建议,请在 GitHub 仓库 提交 issue 或 pull request。