Skip to content

Commit 8ba3968

Browse files
committed
docs: add suggestion for markdown links (close #58)
1 parent c7fcf2d commit 8ba3968

File tree

2 files changed

+46
-18
lines changed

2 files changed

+46
-18
lines changed

docs/guide/markdown.md

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,29 +47,35 @@ Take our documentation source files as an example:
4747
**Raw Markdown**
4848

4949
```md
50-
[Home](/README.md)
51-
[Guide](/guide/)
50+
<!-- relative path -->
51+
[Home](../README.md)
52+
[Config Reference](../reference/config.md)
5253
[Getting Started](./getting-started.md)
53-
[markdown.links](../reference/config.md#links)
54+
<!-- absolute path -->
55+
[Guide](/guide/README.md)
56+
[Config Reference > markdown.links](/reference/config.md#links)
57+
<!-- URL -->
5458
[GitHub](https://github.com)
5559
```
5660

5761
**Converted to**
5862

5963
```vue
6064
<RouterLink to="/">Home</RouterLink>
61-
<RouterLink to="/guide/">Guide</RouterLink>
65+
<RouterLink to="/reference/config.html">Config Reference</RouterLink>
6266
<RouterLink to="/guide/getting-started.html">Getting Started</RouterLink>
63-
<RouterLink to="/reference/config.html#links">markdown.links</RouterLink>
67+
<RouterLink to="/guide/">Guide</RouterLink>
68+
<RouterLink to="/reference/config.html#links">Config Reference &gt; markdown.links</RouterLink>
6469
<a href="https://github.com" target="_blank" rel="noopener noreferrer">GitHub<OutboundLink/></a>
6570
```
6671

6772
**Rendered as**
6873

69-
[Home](/README.md)
70-
[Guide](/guide/)
74+
[Home](../README.md)
75+
[Config Reference](../reference/config.md)
7176
[Getting Started](./getting-started.md)
72-
[markdown.links](../reference/config.md#links)
77+
[Guide](/guide/README.md)
78+
[Config Reference > markdown.links](/reference/config.md#links)
7379
[GitHub](https://github.com)
7480

7581
**Explanation**
@@ -78,6 +84,14 @@ Take our documentation source files as an example:
7884
- Internal links to `.md` files will be converted to the [page route path](./page.md#routing), and both absolute path and relative path are supported.
7985
- External links will get `target="_blank" rel="noopener noreferrer"` attrs and a <OutboundLink /> indicator.
8086

87+
**Suggestion**
88+
89+
Try to use relative paths instead of absolute paths for internal links.
90+
91+
- Relative paths are a valid links to the target files, and they can navigate correctly when browsing the source files in your editor or repository.
92+
- Relative paths are consistent in different locales, so you don't need to change the locale path when translating your content.
93+
- When using absolute paths, if the [base](../reference/config.md#base) of your site is not `"/"`, you will need to prepend the `base` manually or use [base helper](./assets.md#base-helper).
94+
8195
::: tip
8296
This links extension is supported by our built-in plugin.
8397

docs/zh/guide/markdown.md

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,37 +48,51 @@ VuePress 会使用 [markdown-it](https://github.com/markdown-it/markdown-it) 来
4848
**原始 Markdown**
4949

5050
```md
51-
[首页](/zh/README.md)
52-
[指南](/zh/guide/)
51+
<!-- 相对路径 -->
52+
[首页](../README.md)
53+
[配置參考](../reference/config.md)
5354
[快速上手](./getting-started.md)
54-
[markdown.links](../reference/config.md#links)
55-
[GitHub](https://github.com)
55+
<!-- 绝对路径 -->
56+
[指南](/zh/guide/README.md)
57+
[配置參考 > markdown.links](/zh/reference/config.md#links)
58+
<!-- URL -->
59+
[GitHub](https://github.com)
5660
```
5761

5862
**转换为**
5963

6064
```vue
6165
<RouterLink to="/zh/">首页</RouterLink>
62-
<RouterLink to="/zh/guide/">指南</RouterLink>
66+
<RouterLink to="/zh/reference/config.html">配置參考</RouterLink>
6367
<RouterLink to="/zh/guide/getting-started.html">快速上手</RouterLink>
64-
<RouterLink to="/zh/reference/config.html#links">markdown.links</RouterLink>
68+
<RouterLink to="/zh/guide/">指南</RouterLink>
69+
<RouterLink to="/zh/reference/config.html#links">配置參考 &gt; markdown.links</RouterLink>
6570
<a href="https://github.com" target="_blank" rel="noopener noreferrer">GitHub<OutboundLink/></a>
6671
```
6772

6873
**渲染为**
6974

70-
[首页](/zh/README.md)
71-
[指南](/zh/guide/)
75+
[首页](../README.md)
76+
[配置參考](../reference/config.md)
7277
[快速上手](./getting-started.md)
73-
[markdown.links](../reference/config.md#links)
74-
[GitHub](https://github.com)
78+
[指南](/zh/guide/README.md)
79+
[配置參考 > markdown.links](/zh/reference/config.md#links)
80+
[GitHub](https://github.com)
7581

7682
**解释**
7783

7884
- 内部链接会被转换为 `<RouterLink>` 以便进行 SPA 导航。
7985
- 指向 `.md` 文件的内部链接会被转换为目标页面的 [路由路径](./page.md#路由),并且支持绝对路径和相对路径。
8086
- 外部链接会被添加 `target="_blank" rel="noopener noreferrer"` 属性和一个 <OutboundLink /> 标记。
8187

88+
**建议**
89+
90+
对于内部链接,尽可能使用相对路径而不是绝对路径。
91+
92+
- 相对路径是指向目标文件的有效链接,在你的编辑器或者代码仓库中浏览源文件时也可以正确跳转。
93+
- 相对路径在不同 locales 下都是一致的,这样在翻译你的内容时就不需要修改 locale 路径了。
94+
- 在使用绝对路径时,如果你站点的 [base](../reference/config.md#base) 不是 `"/"`,你需要手动添加 `base` 或者使用 [base helper](./assets.md#base-helper)
95+
8296
::: tip
8397
链接扩展是由我们的内置插件支持的。
8498

0 commit comments

Comments
 (0)