From fe52fa34201dcfa87ac4886fe285331f0ef89ba8 Mon Sep 17 00:00:00 2001 From: Divyansh Singh <40380293+brc-dd@users.noreply.github.com> Date: Fri, 20 Jan 2023 23:20:45 +0530 Subject: [PATCH] feat(build): allow ignoring only localhost dead links (#1821) --- docs/config/app-configs.md | 4 ++-- src/node/config.ts | 2 +- src/node/markdownToVue.ts | 5 ++++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/docs/config/app-configs.md b/docs/config/app-configs.md index 73ee2d41..2671f678 100644 --- a/docs/config/app-configs.md +++ b/docs/config/app-configs.md @@ -86,10 +86,10 @@ type HeadConfig = ## ignoreDeadLinks -- Type: `boolean` +- Type: `boolean | 'localhostLinks'` - Default: `false` -When set to `true`, VitePress will not fail builds due to dead 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 export default { diff --git a/src/node/config.ts b/src/node/config.ts index b1c8e90a..acf1dd53 100644 --- a/src/node/config.ts +++ b/src/node/config.ts @@ -73,7 +73,7 @@ export interface UserConfig * * @default false */ - ignoreDeadLinks?: boolean + ignoreDeadLinks?: boolean | 'localhostLinks' /** * @experimental diff --git a/src/node/markdownToVue.ts b/src/node/markdownToVue.ts index 70b185a5..b6792eaa 100644 --- a/src/node/markdownToVue.ts +++ b/src/node/markdownToVue.ts @@ -115,7 +115,10 @@ export async function createMarkdownToVueRenderFn( for (let url of links) { if (/\.(?!html|md)\w+($|\?)/i.test(url)) continue - if (url.replace(EXTERNAL_URL_RE, '').startsWith('//localhost:')) { + if ( + siteConfig?.ignoreDeadLinks !== 'localhostLinks' && + url.replace(EXTERNAL_URL_RE, '').startsWith('//localhost:') + ) { recordDeadLink(url) continue }