Skip to content

Commit 97c9209

Browse files
committed
feat: support disable in checkLink
1 parent 538dfcc commit 97c9209

File tree

6 files changed

+32
-14
lines changed

6 files changed

+32
-14
lines changed

docs/.island/config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ export default defineConfig({
1818
markdown: {
1919
rehypePlugins: [],
2020
remarkPlugins: []
21-
// checkLink: {}
2221
},
2322
route: {
2423
exclude: ['custom.tsx', '**/fragments/**']

docs/en/api/config-extension.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ export default defineConfig({
197197
- Type: `Object`
198198
- default: `null`
199199

200-
Whether to enable the link check of the document, this configuration only takes effect when building the development environment code.
200+
Configure the dead link check behavior of the document.
201201

202202
When a link in the documentation is not accessible properly, an error is thrown and the build is terminated.
203203

@@ -209,6 +209,10 @@ export default defineConfig({
209209
checkLink: {
210210
exclude: ['github.com'],
211211
timeout: 30000
212+
},
213+
checkLink: {
214+
// will close the dead link check
215+
disable: true
212216
}
213217
}
214218
});

docs/zh/api/config-extension.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ export default defineConfig({
197197
- Type: `Object`
198198
- default: `null`
199199

200-
是否开启文档的链接检查,该配置仅在构建开发环境代码时生效
200+
配置文档的链接检查功能
201201

202202
当文档中的链接无法正常访问时,会抛出错误并终止构建。
203203

@@ -209,6 +209,10 @@ export default defineConfig({
209209
checkLink: {
210210
exclude: ['github.com'],
211211
timeout: 30000
212+
},
213+
checkLink: {
214+
// 将会关闭死链检查功能
215+
disable: true
212216
}
213217
}
214218
});

src/node/plugin-island/config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
ISLAND_JSX_RUNTIME_PATH,
88
isProduction,
99
PUBLIC_DIR,
10-
ROUTE_PATH,
1110
SHARED_PATH
1211
} from '../constants';
1312
import { Plugin, UserConfig } from 'vite';

src/node/plugin-mdx/remarkPlugins/deadLinks.ts

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,39 @@
1-
import { MarkdownOptions } from './../../../shared/types/index';
21
import { normalizeRoutePath } from '../../plugin-routes/RouteService';
3-
import { isProduction } from '../../../node/constants';
42
import type { Plugin } from 'unified';
53
import { visit } from 'unist-util-visit';
64
import { routeService } from '../../plugin-routes';
75
import checkLinks from 'check-links';
86
import ora from 'ora';
7+
import { MarkdownOptions } from 'shared/types/index';
98

109
/**
1110
* Remark plugin to normalize a link href
1211
*/
1312
export const remarkCheckDeadLinks: Plugin<
1413
[{ checkLink: MarkdownOptions['checkLink'] }]
1514
> = ({ checkLink }) => {
16-
if (!checkLink || !isProduction()) return;
15+
if (checkLink?.disable) {
16+
return;
17+
}
18+
19+
const { exclude = [], timeout = 10000 } = checkLink || {};
1720

1821
return async (tree) => {
1922
const externalLinks: string[] = [];
2023
const internalLinks: string[] = [];
2124

2225
visit(tree, 'link', (node: { url: string }) => {
2326
const url = node.url;
24-
if (!url) return;
25-
if (internalLinks.includes(url) || externalLinks.includes(url)) return;
27+
if (!url) {
28+
return;
29+
}
30+
if (internalLinks.includes(url) || externalLinks.includes(url)) {
31+
return;
32+
}
2633

2734
if (
28-
checkLink.exclude &&
29-
checkLink.exclude.some((skipPattern: string | RegExp) =>
35+
exclude &&
36+
exclude.some((skipPattern: string | RegExp) =>
3037
new RegExp(skipPattern).test(url)
3138
)
3239
) {
@@ -54,12 +61,16 @@ export const remarkCheckDeadLinks: Plugin<
5461

5562
// If the timeout is set too short, some links will be judged as dead links
5663
const results = await checkLinks(externalLinks, {
57-
timeout: checkLink?.timeout || 30000
64+
timeout
5865
});
5966
Object.keys(results).forEach((url) => {
6067
const result = results[url];
61-
if (result.status !== 'dead') return;
62-
if (!externalLinks.includes(url)) return;
68+
if (result.status !== 'dead') {
69+
return;
70+
}
71+
if (!externalLinks.includes(url)) {
72+
return;
73+
}
6374
errorInfos.push(`External link to ${url} is dead`);
6475
});
6576

src/shared/types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,5 +201,6 @@ export interface MarkdownOptions {
201201
checkLink?: {
202202
exclude?: (string | RegExp)[];
203203
timeout?: number;
204+
disable?: true;
204205
};
205206
}

0 commit comments

Comments
 (0)