We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 5a4700a + 0f82b53 commit 923619cCopy full SHA for 923619c
packages/client/src/components/RouteLink.ts
@@ -1,4 +1,3 @@
1
-import { removeLeadingSlash } from '@vuepress/shared'
2
import { computed, defineComponent, h } from 'vue'
3
import type { SlotsType, VNode } from 'vue'
4
import { useRoute, useRouter } from 'vue-router'
@@ -92,7 +91,7 @@ export const RouteLink = defineComponent({
92
91
const path = computed(() =>
93
props.to.startsWith('#') || props.to.startsWith('?')
94
? props.to
95
- : `${__VUEPRESS_BASE__}${removeLeadingSlash(resolveRoutePath(props.to, route.path))}`,
+ : `${__VUEPRESS_BASE__}${resolveRoutePath(props.to, route.path).substring(1)}`,
96
)
97
98
return () =>
packages/shared/src/utils/index.ts
@@ -2,11 +2,11 @@ export * from './dedupeHead.js'
export * from './ensureLeadingSlash.js'
export * from './ensureEndingSlash.js'
export * from './formatDateString.js'
5
+export * from './inferRoutePath.js'
6
export * from './isLinkExternal.js'
7
export * from './isLinkHttp.js'
8
export * from './isLinkWithProtocol.js'
9
export * from './isPlainObject.js'
-export * from './inferRoutePath.js'
10
export * from './normalizeRoutePath.js'
11
export * from './omit.js'
12
export * from './removeEndingSlash.js'
packages/shared/src/utils/inferRoutePath.ts
@@ -1,3 +1,6 @@
+/**
+ * Infer route path according to the given (markdown file) path
+ */
export const inferRoutePath = (path: string): string => {
// if the pathname is empty or ends with `/`, return as is
if (!path || path.endsWith('/')) return path
packages/shared/src/utils/isLinkExternal.ts
@@ -1,23 +1,13 @@
-import { isLinkHttp } from './isLinkHttp.js'
+import { isLinkWithProtocol } from './isLinkWithProtocol.js'
const markdownLinkRegexp = /.md((\?|#).*)?$/
/**
* Determine a link is external or not
*/
-export const isLinkExternal = (link: string, base = '/'): boolean => {
- if (isLinkHttp(link)) {
- return true
- }
-
+export const isLinkExternal = (link: string, base = '/'): boolean =>
+ isLinkWithProtocol(link) ||
13
// absolute link that does not start with `base` and does not end with `.md`
14
- if (
15
- link.startsWith('/') &&
+ (link.startsWith('/') &&
16
!link.startsWith(base) &&
17
- !markdownLinkRegexp.test(link)
18
- ) {
19
20
21
22
- return false
23
-}
+ !markdownLinkRegexp.test(link))
packages/shared/tests/isLinkExternal.spec.ts
@@ -20,13 +20,13 @@ const testCases: [
[['//foobar.com/base/README.md', '/base/'], true],
// links with other protocols
- [['mailto:foobar', '/base/'], false],
24
- [['tel:foobar', '/base/'], false],
25
- [['ftp://foobar.com'], false],
26
- [['ftp://foobar.com', '/base/'], false],
27
- [['ftp://foobar.com/base/README.md'], false],
28
- [['ftp://foobar.com/base/README.md', '/base/'], false],
29
- [['ms-windows-store://home', '/base/'], false],
+ [['mailto:foobar', '/base/'], true],
+ [['tel:foobar', '/base/'], true],
+ [['ftp://foobar.com'], true],
+ [['ftp://foobar.com', '/base/'], true],
+ [['ftp://foobar.com/base/README.md'], true],
+ [['ftp://foobar.com/base/README.md', '/base/'], true],
+ [['ms-windows-store://home', '/base/'], true],
30
31
// absolute links
32
[['/foo/bar'], false],
0 commit comments