Skip to content

Commit

Permalink
Merge branch 'main' into markdown-links
Browse files Browse the repository at this point in the history
  • Loading branch information
Mister-Hope committed May 14, 2024
2 parents 1227d20 + 8eb722f commit ffe25c8
Show file tree
Hide file tree
Showing 19 changed files with 970 additions and 884 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node: ['18', '20']
node: ['18', '20', '22']

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

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node: ['18', '20']
node: ['18', '20', '22']
bundler: ['webpack', 'vite']

runs-on: ${{ matrix.os }}
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# VuePress

[![check](https://github.com/vuepress/core/workflows/check/badge.svg)](https://github.com/vuepress/core/actions/workflows/check.yml?query=workflow%3Acheck)
[![check](https://github.com/vuepress/core/actions/workflows/check.yml/badge.svg?branch=main)](https://github.com/vuepress/core/actions/workflows/check.yml)
[![e2e](https://github.com/vuepress/core/actions/workflows/e2e.yml/badge.svg?branch=main)](https://github.com/vuepress/core/actions/workflows/e2e.yml)
[![npm](https://badgen.net/npm/v/vuepress/next)](https://www.npmjs.com/package/vuepress)
[![coverage](https://coveralls.io/repos/github/vuepress/core/badge.svg?branch=main)](https://coveralls.io/github/vuepress/core?branch=main)
[![license](https://badgen.net/github/license/vuepress/core)](https://github.com/vuepress/core/blob/main/LICENSE)
Expand Down
6 changes: 3 additions & 3 deletions e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
"@vuepress-e2e/conditional-exports": "file:./modules/conditional-exports",
"@vuepress/bundler-vite": "workspace:*",
"@vuepress/bundler-webpack": "workspace:*",
"sass": "^1.75.0",
"sass": "^1.77.1",
"sass-loader": "^14.2.1",
"vue": "^3.4.23",
"vue": "^3.4.27",
"vuepress": "workspace:*"
},
"devDependencies": {
"@playwright/test": "^1.43.1",
"@playwright/test": "^1.44.0",
"anywhere": "^1.6.0",
"cross-env": "^7.0.3"
}
Expand Down
29 changes: 13 additions & 16 deletions e2e/tests/components/auto-link.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,33 @@ test.beforeEach(async ({ page }) => {
})

test('should render route-link correctly', async ({ page }) => {
for (const el of await page
.locator('.e2e-theme-content #route-link a')
.all()) {
const locator = page.locator('.e2e-theme-content #route-link a')

for (const el of await locator.all()) {
await expect(el).toHaveAttribute('class', /route-link/)
}
})

test('should render external-link correctly', async ({ page }) => {
for (const el of await page
.locator('.e2e-theme-content #external-link a')
.all()) {
const locator = page.locator('.e2e-theme-content #external-link a')

for (const el of await locator.all()) {
await expect(el).toHaveAttribute('class', /external-link/)
}
})

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

await expect(await locator.nth(0)).toHaveText('text1')
await expect(await locator.nth(0)).toHaveAttribute('href', BASE)
await expect(await locator.nth(0)).toHaveAttribute('aria-label', 'label')
await expect(locator.nth(0)).toHaveText('text1')
await expect(locator.nth(0)).toHaveAttribute('href', BASE)
await expect(locator.nth(0)).toHaveAttribute('aria-label', 'label')

await expect(await locator.nth(1)).toHaveText('text2')
await expect(await locator.nth(1)).toHaveAttribute(
await expect(locator.nth(1)).toHaveText('text2')
await expect(locator.nth(1)).toHaveAttribute(
'href',
'https://example.com/test/',
)
await expect(await locator.nth(1)).toHaveAttribute('target', '_blank')
await expect(await locator.nth(1)).toHaveAttribute(
'rel',
'noopener noreferrer',
)
await expect(locator.nth(1)).toHaveAttribute('target', '_blank')
await expect(locator.nth(1)).toHaveAttribute('rel', 'noopener noreferrer')
})
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,30 @@
},
"prettier": "prettier-config-vuepress",
"devDependencies": {
"@commitlint/cli": "^19.2.2",
"@commitlint/cli": "^19.3.0",
"@commitlint/config-conventional": "^19.2.2",
"@commitlint/types": "^19.0.3",
"@types/node": "^20.12.7",
"@types/webpack-env": "^1.18.4",
"@vitest/coverage-istanbul": "^1.5.0",
"bumpp": "^9.4.0",
"conventional-changelog-cli": "^4.1.0",
"@types/node": "^20.12.11",
"@types/webpack-env": "^1.18.5",
"@vitest/coverage-istanbul": "^1.6.0",
"bumpp": "^9.4.1",
"conventional-changelog-cli": "^5.0.0",
"eslint": "^8.57.0",
"eslint-config-vuepress": "^4.10.1",
"eslint-config-vuepress-typescript": "^4.10.1",
"husky": "^9.0.11",
"lint-staged": "^15.2.2",
"prettier": "^3.2.5",
"prettier-config-vuepress": "^4.4.0",
"rimraf": "^5.0.5",
"rimraf": "^5.0.7",
"sort-package-json": "^2.10.0",
"tsconfig-vuepress": "^4.5.0",
"tsup": "^8.0.2",
"typescript": "^5.4.5",
"vite": "~5.2.10",
"vitest": "^1.5.0"
"vite": "~5.2.11",
"vitest": "^1.6.0"
},
"packageManager": "pnpm@9.0.4",
"packageManager": "pnpm@9.1.1",
"engines": {
"node": ">=18.16.0"
}
Expand Down
8 changes: 4 additions & 4 deletions packages/bundler-vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@
"autoprefixer": "^10.4.19",
"connect-history-api-fallback": "^2.0.0",
"postcss": "^8.4.38",
"postcss-load-config": "^5.0.3",
"rollup": "^4.16.0",
"vite": "~5.2.10",
"vue": "^3.4.23",
"postcss-load-config": "^5.1.0",
"rollup": "^4.17.2",
"vite": "~5.2.11",
"vue": "^3.4.27",
"vue-router": "^4.3.2"
},
"publishConfig": {
Expand Down
4 changes: 2 additions & 2 deletions packages/bundler-webpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
},
"dependencies": {
"@types/express": "^4.17.21",
"@types/webpack-env": "^1.18.4",
"@types/webpack-env": "^1.18.5",
"@vuepress/client": "workspace:*",
"@vuepress/core": "workspace:*",
"@vuepress/shared": "workspace:*",
Expand All @@ -54,7 +54,7 @@
"postcss-csso": "^6.0.1",
"postcss-loader": "^8.1.1",
"style-loader": "^4.0.0",
"vue": "^3.4.23",
"vue": "^3.4.27",
"vue-loader": "^17.4.2",
"vue-router": "^4.3.2",
"webpack": "^5.91.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"@vuepress/utils": "workspace:*",
"cac": "^6.7.14",
"chokidar": "^3.6.0",
"envinfo": "^7.12.0",
"envinfo": "^7.13.0",
"esbuild": "~0.20.2"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"dependencies": {
"@vue/devtools-api": "^6.6.1",
"@vuepress/shared": "workspace:*",
"vue": "^3.4.23",
"vue": "^3.4.27",
"vue-router": "^4.3.2"
},
"publishConfig": {
Expand Down
117 changes: 48 additions & 69 deletions packages/client/src/components/AutoLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,123 +5,104 @@ import { useRoute } from 'vue-router'
import { useSiteData } from '../composables/index.js'
import { RouteLink } from './RouteLink.js'

export interface AutoLinkConfig {
export interface AutoLinkProps {
/**
* Text of item
*
* 项目文字
* Pattern to determine if the link should be active, which has higher priority than `exact`
*/
text: string
activeMatch?: string | RegExp

/**
* Aria label of item
*
* 项目无障碍标签
* The `aria-label` attribute
*/
ariaLabel?: string

/**
* Link of item
*
* 当前页面链接
* Whether the link should be active only if the url is an exact match
*/
exact?: boolean

/**
* URL of the auto link
*/
link: string

/**
* Rel of `<a>` tag
*
* `<a>` 标签的 `rel` 属性
* The `rel` attribute
*/
rel?: string

/**
* Target of `<a>` tag
*
* `<a>` 标签的 `target` 属性
* The `target` attribute
*/
target?: string

/**
* Regexp mode to be active
*
* 匹配激活的正则表达式
* Text of the auto link
*/
activeMatch?: string
text: string
}

/**
* Component to render a link automatically according to the link type
*
* - If the link is internal, it will be rendered as a `<RouteLink>`
* - If the link is external, it will be rendered as a normal `<a>` tag
*/
export const AutoLink = defineComponent({
name: 'AutoLink',

props: {
/**
* Text of item
*
* 项目文字
* Pattern to determine if the link should be active, which has higher priority than `exact`
*/
text: {
type: String,
required: true,
activeMatch: {
type: [String, RegExp],
default: '',
},

/**
* Link of item
*
* 当前页面链接
* The `aria-label` attribute
*/
link: {
ariaLabel: {
type: String,
required: true,
default: '',
},

/**
* Aria label of item
*
* 项目无障碍标签
* Whether the link should be active only if the url is an exact match
*/
ariaLabel: {
exact: Boolean,

/**
* URL of the auto link
*/
link: {
type: String,
default: '',
required: true,
},

/**
* Rel of `<a>` tag
*
* `<a>` 标签的 `rel` 属性
* The `rel` attribute
*/
rel: {
type: String,
default: '',
},

/**
* Target of `<a>` tag
*
* `<a>` 标签的 `target` 属性
* The `target` attribute
*/
target: {
type: String,
default: '',
},

/**
* Whether it's active only when exact match
*
* 是否当恰好匹配时激活
*/
exact: Boolean,

/**
* Regexp mode to be active
*
* @description has higher priority than exact
*
* 匹配激活的正则表达式
*
* @description 比 exact 的优先级更高
* Text of the auto link
*/
activeMatch: {
type: [String, RegExp],
default: '',
text: {
type: String,
required: true,
},
},

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

if (props.activeMatch)
if (props.activeMatch) {
return (
props.activeMatch instanceof RegExp
? props.activeMatch
: new RegExp(props.activeMatch, 'u')
).test(route.path)
}

// If this link is active in subpath
if (shouldBeActiveInSubpath.value)
if (shouldBeActiveInSubpath.value) {
return route.path.startsWith(props.link)
}

return route.path === props.link
})

return (): VNode => {
return () => {
const { before, after, default: defaultSlot } = slots

const content = defaultSlot?.() || [
before ? before() : null,
props.text,
after?.(),
]
const content = defaultSlot?.() || [before?.(), props.text, after?.()]

return isInternal.value
? h(
Expand All @@ -216,9 +195,9 @@ export const AutoLink = defineComponent({
{
'class': 'auto-link external-link',
'href': props.link,
'aria-label': linkAriaLabel.value,
'rel': linkRel.value,
'target': linkTarget.value,
'aria-label': linkAriaLabel.value,
},
content,
)
Expand Down

0 comments on commit ffe25c8

Please sign in to comment.