Skip to content

Commit 9eac9a9

Browse files
committed
Merge branch 'markdown-links' into route-option
2 parents 212aa84 + ffe25c8 commit 9eac9a9

File tree

22 files changed

+1020
-930
lines changed

22 files changed

+1020
-930
lines changed

.github/workflows/check.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
fail-fast: false
1616
matrix:
1717
os: [ubuntu-latest, windows-latest, macos-latest]
18-
node: ['18', '20']
18+
node: ['18', '20', '22']
1919

2020
runs-on: ${{ matrix.os }}
2121

.github/workflows/e2e.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
fail-fast: false
1616
matrix:
1717
os: [ubuntu-latest, windows-latest, macos-latest]
18-
node: ['18', '20']
18+
node: ['18', '20', '22']
1919
bundler: ['webpack', 'vite']
2020

2121
runs-on: ${{ matrix.os }}

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# VuePress
22

3-
[![check](https://github.com/vuepress/core/workflows/check/badge.svg)](https://github.com/vuepress/core/actions/workflows/check.yml?query=workflow%3Acheck)
3+
[![check](https://github.com/vuepress/core/actions/workflows/check.yml/badge.svg?branch=main)](https://github.com/vuepress/core/actions/workflows/check.yml)
4+
[![e2e](https://github.com/vuepress/core/actions/workflows/e2e.yml/badge.svg?branch=main)](https://github.com/vuepress/core/actions/workflows/e2e.yml)
45
[![npm](https://badgen.net/npm/v/vuepress/next)](https://www.npmjs.com/package/vuepress)
56
[![coverage](https://coveralls.io/repos/github/vuepress/core/badge.svg?branch=main)](https://coveralls.io/github/vuepress/core?branch=main)
67
[![license](https://badgen.net/github/license/vuepress/core)](https://github.com/vuepress/core/blob/main/LICENSE)

e2e/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@
1919
"@vuepress-e2e/conditional-exports": "file:./modules/conditional-exports",
2020
"@vuepress/bundler-vite": "workspace:*",
2121
"@vuepress/bundler-webpack": "workspace:*",
22-
"sass": "^1.75.0",
22+
"sass": "^1.77.1",
2323
"sass-loader": "^14.2.1",
24-
"vue": "^3.4.23",
24+
"vue": "^3.4.27",
2525
"vuepress": "workspace:*"
2626
},
2727
"devDependencies": {
28-
"@playwright/test": "^1.43.1",
28+
"@playwright/test": "^1.44.0",
2929
"anywhere": "^1.6.0",
3030
"cross-env": "^7.0.3"
3131
}

e2e/tests/components/auto-link.spec.ts

+13-16
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,33 @@ test.beforeEach(async ({ page }) => {
66
})
77

88
test('should render route-link correctly', async ({ page }) => {
9-
for (const el of await page
10-
.locator('.e2e-theme-content #route-link a')
11-
.all()) {
9+
const locator = page.locator('.e2e-theme-content #route-link a')
10+
11+
for (const el of await locator.all()) {
1212
await expect(el).toHaveAttribute('class', /route-link/)
1313
}
1414
})
1515

1616
test('should render external-link correctly', async ({ page }) => {
17-
for (const el of await page
18-
.locator('.e2e-theme-content #external-link a')
19-
.all()) {
17+
const locator = page.locator('.e2e-theme-content #external-link a')
18+
19+
for (const el of await locator.all()) {
2020
await expect(el).toHaveAttribute('class', /external-link/)
2121
}
2222
})
2323

2424
test('should render config correctly', async ({ page }) => {
2525
const locator = page.locator('.e2e-theme-content #config a')
2626

27-
await expect(await locator.nth(0)).toHaveText('text1')
28-
await expect(await locator.nth(0)).toHaveAttribute('href', BASE)
29-
await expect(await locator.nth(0)).toHaveAttribute('aria-label', 'label')
27+
await expect(locator.nth(0)).toHaveText('text1')
28+
await expect(locator.nth(0)).toHaveAttribute('href', BASE)
29+
await expect(locator.nth(0)).toHaveAttribute('aria-label', 'label')
3030

31-
await expect(await locator.nth(1)).toHaveText('text2')
32-
await expect(await locator.nth(1)).toHaveAttribute(
31+
await expect(locator.nth(1)).toHaveText('text2')
32+
await expect(locator.nth(1)).toHaveAttribute(
3333
'href',
3434
'https://example.com/test/',
3535
)
36-
await expect(await locator.nth(1)).toHaveAttribute('target', '_blank')
37-
await expect(await locator.nth(1)).toHaveAttribute(
38-
'rel',
39-
'noopener noreferrer',
40-
)
36+
await expect(locator.nth(1)).toHaveAttribute('target', '_blank')
37+
await expect(locator.nth(1)).toHaveAttribute('rel', 'noopener noreferrer')
4138
})

package.json

+10-10
Original file line numberDiff line numberDiff line change
@@ -30,30 +30,30 @@
3030
},
3131
"prettier": "prettier-config-vuepress",
3232
"devDependencies": {
33-
"@commitlint/cli": "^19.2.2",
33+
"@commitlint/cli": "^19.3.0",
3434
"@commitlint/config-conventional": "^19.2.2",
3535
"@commitlint/types": "^19.0.3",
36-
"@types/node": "^20.12.7",
37-
"@types/webpack-env": "^1.18.4",
38-
"@vitest/coverage-istanbul": "^1.5.0",
39-
"bumpp": "^9.4.0",
40-
"conventional-changelog-cli": "^4.1.0",
36+
"@types/node": "^20.12.11",
37+
"@types/webpack-env": "^1.18.5",
38+
"@vitest/coverage-istanbul": "^1.6.0",
39+
"bumpp": "^9.4.1",
40+
"conventional-changelog-cli": "^5.0.0",
4141
"eslint": "^8.57.0",
4242
"eslint-config-vuepress": "^4.10.1",
4343
"eslint-config-vuepress-typescript": "^4.10.1",
4444
"husky": "^9.0.11",
4545
"lint-staged": "^15.2.2",
4646
"prettier": "^3.2.5",
4747
"prettier-config-vuepress": "^4.4.0",
48-
"rimraf": "^5.0.5",
48+
"rimraf": "^5.0.7",
4949
"sort-package-json": "^2.10.0",
5050
"tsconfig-vuepress": "^4.5.0",
5151
"tsup": "^8.0.2",
5252
"typescript": "^5.4.5",
53-
"vite": "~5.2.10",
54-
"vitest": "^1.5.0"
53+
"vite": "~5.2.11",
54+
"vitest": "^1.6.0"
5555
},
56-
"packageManager": "pnpm@9.0.4",
56+
"packageManager": "pnpm@9.1.1",
5757
"engines": {
5858
"node": ">=18.16.0"
5959
}

packages/bundler-vite/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@
4141
"autoprefixer": "^10.4.19",
4242
"connect-history-api-fallback": "^2.0.0",
4343
"postcss": "^8.4.38",
44-
"postcss-load-config": "^5.0.3",
45-
"rollup": "^4.16.0",
46-
"vite": "~5.2.10",
47-
"vue": "^3.4.23",
44+
"postcss-load-config": "^5.1.0",
45+
"rollup": "^4.17.2",
46+
"vite": "~5.2.11",
47+
"vue": "^3.4.27",
4848
"vue-router": "^4.3.2"
4949
},
5050
"publishConfig": {

packages/bundler-webpack/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
},
3838
"dependencies": {
3939
"@types/express": "^4.17.21",
40-
"@types/webpack-env": "^1.18.4",
40+
"@types/webpack-env": "^1.18.5",
4141
"@vuepress/client": "workspace:*",
4242
"@vuepress/core": "workspace:*",
4343
"@vuepress/shared": "workspace:*",
@@ -54,7 +54,7 @@
5454
"postcss-csso": "^6.0.1",
5555
"postcss-loader": "^8.1.1",
5656
"style-loader": "^4.0.0",
57-
"vue": "^3.4.23",
57+
"vue": "^3.4.27",
5858
"vue-loader": "^17.4.2",
5959
"vue-router": "^4.3.2",
6060
"webpack": "^5.91.0",

packages/cli/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"@vuepress/utils": "workspace:*",
4242
"cac": "^6.7.14",
4343
"chokidar": "^3.6.0",
44-
"envinfo": "^7.12.0",
44+
"envinfo": "^7.13.0",
4545
"esbuild": "~0.20.2"
4646
},
4747
"devDependencies": {

packages/client/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"dependencies": {
4040
"@vue/devtools-api": "^6.6.1",
4141
"@vuepress/shared": "workspace:*",
42-
"vue": "^3.4.23",
42+
"vue": "^3.4.27",
4343
"vue-router": "^4.3.2"
4444
},
4545
"publishConfig": {

packages/client/src/components/AutoLink.ts

+48-69
Original file line numberDiff line numberDiff line change
@@ -5,123 +5,104 @@ import { useRoute } from 'vue-router'
55
import { useSiteData } from '../composables/index.js'
66
import { RouteLink } from './RouteLink.js'
77

8-
export interface AutoLinkConfig {
8+
export interface AutoLinkProps {
99
/**
10-
* Text of item
11-
*
12-
* 项目文字
10+
* Pattern to determine if the link should be active, which has higher priority than `exact`
1311
*/
14-
text: string
12+
activeMatch?: string | RegExp
1513

1614
/**
17-
* Aria label of item
18-
*
19-
* 项目无障碍标签
15+
* The `aria-label` attribute
2016
*/
2117
ariaLabel?: string
2218

2319
/**
24-
* Link of item
25-
*
26-
* 当前页面链接
20+
* Whether the link should be active only if the url is an exact match
21+
*/
22+
exact?: boolean
23+
24+
/**
25+
* URL of the auto link
2726
*/
2827
link: string
2928

3029
/**
31-
* Rel of `<a>` tag
32-
*
33-
* `<a>` 标签的 `rel` 属性
30+
* The `rel` attribute
3431
*/
3532
rel?: string
3633

3734
/**
38-
* Target of `<a>` tag
39-
*
40-
* `<a>` 标签的 `target` 属性
35+
* The `target` attribute
4136
*/
4237
target?: string
4338

4439
/**
45-
* Regexp mode to be active
46-
*
47-
* 匹配激活的正则表达式
40+
* Text of the auto link
4841
*/
49-
activeMatch?: string
42+
text: string
5043
}
5144

45+
/**
46+
* Component to render a link automatically according to the link type
47+
*
48+
* - If the link is internal, it will be rendered as a `<RouteLink>`
49+
* - If the link is external, it will be rendered as a normal `<a>` tag
50+
*/
5251
export const AutoLink = defineComponent({
5352
name: 'AutoLink',
5453

5554
props: {
5655
/**
57-
* Text of item
58-
*
59-
* 项目文字
56+
* Pattern to determine if the link should be active, which has higher priority than `exact`
6057
*/
61-
text: {
62-
type: String,
63-
required: true,
58+
activeMatch: {
59+
type: [String, RegExp],
60+
default: '',
6461
},
6562

6663
/**
67-
* Link of item
68-
*
69-
* 当前页面链接
64+
* The `aria-label` attribute
7065
*/
71-
link: {
66+
ariaLabel: {
7267
type: String,
73-
required: true,
68+
default: '',
7469
},
7570

7671
/**
77-
* Aria label of item
78-
*
79-
* 项目无障碍标签
72+
* Whether the link should be active only if the url is an exact match
8073
*/
81-
ariaLabel: {
74+
exact: Boolean,
75+
76+
/**
77+
* URL of the auto link
78+
*/
79+
link: {
8280
type: String,
83-
default: '',
81+
required: true,
8482
},
8583

8684
/**
87-
* Rel of `<a>` tag
88-
*
89-
* `<a>` 标签的 `rel` 属性
85+
* The `rel` attribute
9086
*/
9187
rel: {
9288
type: String,
9389
default: '',
9490
},
9591

9692
/**
97-
* Target of `<a>` tag
98-
*
99-
* `<a>` 标签的 `target` 属性
93+
* The `target` attribute
10094
*/
10195
target: {
10296
type: String,
10397
default: '',
10498
},
10599

106100
/**
107-
* Whether it's active only when exact match
108-
*
109-
* 是否当恰好匹配时激活
110-
*/
111-
exact: Boolean,
112-
113-
/**
114-
* Regexp mode to be active
115-
*
116-
* @description has higher priority than exact
117-
*
118-
* 匹配激活的正则表达式
119-
*
120-
* @description 比 exact 的优先级更高
101+
* Text of the auto link
121102
*/
122-
activeMatch: {
123-
type: [String, RegExp],
124-
default: '',
103+
text: {
104+
type: String,
105+
required: true,
125106
},
126107
},
127108

@@ -177,28 +158,26 @@ export const AutoLink = defineComponent({
177158
const isActive = computed(() => {
178159
if (!isInternal.value) return false
179160

180-
if (props.activeMatch)
161+
if (props.activeMatch) {
181162
return (
182163
props.activeMatch instanceof RegExp
183164
? props.activeMatch
184165
: new RegExp(props.activeMatch, 'u')
185166
).test(route.path)
167+
}
186168

187169
// If this link is active in subpath
188-
if (shouldBeActiveInSubpath.value)
170+
if (shouldBeActiveInSubpath.value) {
189171
return route.path.startsWith(props.link)
172+
}
190173

191174
return route.path === props.link
192175
})
193176

194-
return (): VNode => {
177+
return () => {
195178
const { before, after, default: defaultSlot } = slots
196179

197-
const content = defaultSlot?.() || [
198-
before ? before() : null,
199-
props.text,
200-
after?.(),
201-
]
180+
const content = defaultSlot?.() || [before?.(), props.text, after?.()]
202181

203182
return isInternal.value
204183
? h(
@@ -216,9 +195,9 @@ export const AutoLink = defineComponent({
216195
{
217196
'class': 'auto-link external-link',
218197
'href': props.link,
198+
'aria-label': linkAriaLabel.value,
219199
'rel': linkRel.value,
220200
'target': linkTarget.value,
221-
'aria-label': linkAriaLabel.value,
222201
},
223202
content,
224203
)

0 commit comments

Comments
 (0)