Merge branch 'main' into config-loader

pull/2147/head
John Campion Jr 3 years ago committed by GitHub
commit 3554dd71d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,3 +1,18 @@
# [1.0.0-alpha.63](https://github.com/vuejs/vitepress/compare/v1.0.0-alpha.62...v1.0.0-alpha.63) (2023-03-26)
### Bug Fixes
* **theme:** allow adding html as feature icons ([e5bc1e1](https://github.com/vuejs/vitepress/commit/e5bc1e10862a765f6790f5f08aa2bd76bb258532))
* **theme:** remove label background of code-group tabs ([#2136](https://github.com/vuejs/vitepress/issues/2136)) ([eac03f2](https://github.com/vuejs/vitepress/commit/eac03f26e2d3ab47158ac2528210e95460f6c302))
### Features
* more flexible `ignoreDeadLinks` ([#2135](https://github.com/vuejs/vitepress/issues/2135)) ([3235c23](https://github.com/vuejs/vitepress/commit/3235c23313d81f8f95b91779a48db839c02aa952))
# [1.0.0-alpha.62](https://github.com/vuejs/vitepress/compare/v1.0.0-alpha.61...v1.0.0-alpha.62) (2023-03-25) # [1.0.0-alpha.62](https://github.com/vuejs/vitepress/compare/v1.0.0-alpha.61...v1.0.0-alpha.62) (2023-03-25)

@ -55,6 +55,6 @@ This can be disabled per-page using the `editLink` option on frontmatter:
```yaml ```yaml
--- ---
lastUpdated: false editLink: false
--- ---
``` ```

@ -282,10 +282,12 @@ export default {
### ignoreDeadLinks ### ignoreDeadLinks
- Type: `boolean | 'localhostLinks'` - Type: `boolean | 'localhostLinks' | (string | RegExp | ((link: string) => boolean))[]`
- Default: `false` - Default: `false`
When set to `true`, VitePress will not fail builds due to dead links. When set to `'localhostLinks'`, the build will fail on dead links, but won't check `localhost` links. When set to `true`, VitePress will not fail builds due to dead links.
When set to `'localhostLinks'`, the build will fail on dead links, but won't check `localhost` links.
```ts ```ts
export default { export default {
@ -293,6 +295,25 @@ export default {
} }
``` ```
It can also be an array of extact url string, regex patterns, or custom filter functions.
```ts
export default {
ignoreDeadLinks: [
// ignore exact url "/playground"
'/playground',
// ignore all localhost links
/^https?:\/\/localhost/,
// ignore all links include "/repl/""
/\/repl\//,
// custom function, ignore all links include "ignore"
(url) => {
return url.toLowerCase().includes('ignore')
}
]
}
```
### mpa <Badge type="warning" text="experimental" /> ### mpa <Badge type="warning" text="experimental" />
- Type: `boolean` - Type: `boolean`

@ -1,9 +1,9 @@
{ {
"name": "vitepress", "name": "vitepress",
"version": "1.0.0-alpha.62", "version": "1.0.0-alpha.63",
"description": "Vite & Vue powered static site generator", "description": "Vite & Vue powered static site generator",
"type": "module", "type": "module",
"packageManager": "pnpm@7.30.0", "packageManager": "pnpm@7.30.3",
"main": "dist/node/index.js", "main": "dist/node/index.js",
"types": "types/index.d.ts", "types": "types/index.d.ts",
"exports": { "exports": {

@ -23,7 +23,7 @@ defineProps<{
:height="icon.height" :height="icon.height"
:width="icon.width" :width="icon.width"
/> />
<div v-else-if="icon" class="icon">{{ icon }}</div> <div v-else-if="icon" class="icon" v-html="icon"></div>
<h2 class="title" v-html="title"></h2> <h2 class="title" v-html="title"></h2>
<p v-if="details" class="details" v-html="details"></p> <p v-if="details" class="details" v-html="details"></p>

@ -121,7 +121,7 @@ onContentUpdated(() => {
border: 1px solid var(--vp-c-divider); border: 1px solid var(--vp-c-divider);
border-radius: 8px; border-radius: 8px;
max-height: calc(var(--vp-vh, 100vh) - 86px); max-height: calc(var(--vp-vh, 100vh) - 86px);
overflow: scroll; overflow: hidden auto;
box-shadow: var(--vp-shadow-3); box-shadow: var(--vp-shadow-3);
} }

@ -46,7 +46,6 @@
font-size: 14px; font-size: 14px;
font-weight: 500; font-weight: 500;
color: var(--vp-code-tab-text-color); color: var(--vp-code-tab-text-color);
background-color: var(--vp-code-tab-bg);
white-space: nowrap; white-space: nowrap;
cursor: pointer; cursor: pointer;
transition: color 0.25s; transition: color 0.25s;

@ -85,7 +85,10 @@ export interface UserConfig<ThemeConfig = any>
* *
* @default false * @default false
*/ */
ignoreDeadLinks?: boolean | 'localhostLinks' ignoreDeadLinks?:
| boolean
| 'localhostLinks'
| (string | RegExp | ((link: string) => boolean))[]
/** /**
* Don't force `.html` on URLs. * Don't force `.html` on URLs.

@ -125,19 +125,36 @@ export async function createMarkdownToVueRenderFn(
deadLinks.push(url) deadLinks.push(url)
} }
function shouldIgnoreDeadLink(url: string) {
if (!siteConfig?.ignoreDeadLinks) {
return false
}
if (siteConfig.ignoreDeadLinks === true) {
return true
}
if (siteConfig.ignoreDeadLinks === 'localhostLinks') {
return url.replace(EXTERNAL_URL_RE, '').startsWith('//localhost')
}
return siteConfig.ignoreDeadLinks.some((ignore) => {
if (typeof ignore === 'string') {
return url === ignore
}
if (ignore instanceof RegExp) {
return ignore.test(url)
}
if (typeof ignore === 'function') {
return ignore(url)
}
return false
})
}
if (links) { if (links) {
const dir = path.dirname(file) const dir = path.dirname(file)
for (let url of links) { for (let url of links) {
if (/\.(?!html|md)\w+($|\?)/i.test(url)) continue if (/\.(?!html|md)\w+($|\?)/i.test(url)) continue
if (
siteConfig?.ignoreDeadLinks !== 'localhostLinks' &&
url.replace(EXTERNAL_URL_RE, '').startsWith('//localhost:')
) {
recordDeadLink(url)
continue
}
url = url.replace(/[?#].*$/, '').replace(/\.(html|md)$/, '') url = url.replace(/[?#].*$/, '').replace(/\.(html|md)$/, '')
if (url.endsWith('/')) url += `index` if (url.endsWith('/')) url += `index`
let resolved = decodeURIComponent( let resolved = decodeURIComponent(
@ -151,7 +168,8 @@ export async function createMarkdownToVueRenderFn(
siteConfig?.rewrites.inv[resolved + '.md']?.slice(0, -3) || resolved siteConfig?.rewrites.inv[resolved + '.md']?.slice(0, -3) || resolved
if ( if (
!pages.includes(resolved) && !pages.includes(resolved) &&
!fs.existsSync(path.resolve(dir, publicDir, `${resolved}.html`)) !fs.existsSync(path.resolve(dir, publicDir, `${resolved}.html`)) &&
!shouldIgnoreDeadLink(url)
) { ) {
recordDeadLink(url) recordDeadLink(url)
} }

@ -70,7 +70,6 @@ export async function createVitePressPlugin(
vue: userVuePluginOptions, vue: userVuePluginOptions,
vite: userViteConfig, vite: userViteConfig,
pages, pages,
ignoreDeadLinks,
lastUpdated, lastUpdated,
cleanUrls cleanUrls
} = siteConfig } = siteConfig
@ -195,7 +194,7 @@ export async function createVitePressPlugin(
}, },
renderStart() { renderStart() {
if (hasDeadLinks && !ignoreDeadLinks) { if (hasDeadLinks) {
throw new Error(`One or more pages contain dead links.`) throw new Error(`One or more pages contain dead links.`)
} }
}, },

Loading…
Cancel
Save