@mintlify/cli 4.0.1813 → 4.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/export-scripts/README.classic.md +15 -0
- package/dist/assets/export-scripts/README.md +14 -0
- package/dist/assets/export-scripts/serve.js +114 -0
- package/dist/assets/export-scripts/start-docs.bat +10 -0
- package/dist/assets/export-scripts/start-docs.sh +9 -0
- package/dist/assets/og/Inter-Bold.ttf +0 -0
- package/dist/assets/og/Inter-Medium.ttf +0 -0
- package/dist/assets/og/Inter-Regular.ttf +0 -0
- package/dist/assets/og/Inter-SemiBold.ttf +0 -0
- package/dist/assets/og/PaperMono-Regular.ttf +0 -0
- package/dist/assets/og/index_bg.wasm +0 -0
- package/dist/assets/openChrome.applescript +94 -0
- package/dist/assets/socket.io/socket.io.esm.min.js +7 -0
- package/dist/assets/socket.io/socket.io.esm.min.js.map +1 -0
- package/dist/assets/socket.io/socket.io.js +4907 -0
- package/dist/assets/socket.io/socket.io.js.map +1 -0
- package/dist/assets/socket.io/socket.io.min.js +7 -0
- package/dist/assets/socket.io/socket.io.min.js.map +1 -0
- package/dist/assets/socket.io/socket.io.msgpack.min.js +7 -0
- package/dist/assets/socket.io/socket.io.msgpack.min.js.map +1 -0
- package/dist/assets/xdg-open +1066 -0
- package/dist/assets/yargs-locales/be.json +46 -0
- package/dist/assets/yargs-locales/cs.json +51 -0
- package/dist/assets/yargs-locales/de.json +46 -0
- package/dist/assets/yargs-locales/en.json +55 -0
- package/dist/assets/yargs-locales/es.json +46 -0
- package/dist/assets/yargs-locales/fi.json +49 -0
- package/dist/assets/yargs-locales/fr.json +53 -0
- package/dist/assets/yargs-locales/hi.json +49 -0
- package/dist/assets/yargs-locales/hu.json +46 -0
- package/dist/assets/yargs-locales/id.json +50 -0
- package/dist/assets/yargs-locales/it.json +46 -0
- package/dist/assets/yargs-locales/ja.json +51 -0
- package/dist/assets/yargs-locales/ko.json +49 -0
- package/dist/assets/yargs-locales/nb.json +44 -0
- package/dist/assets/yargs-locales/nl.json +49 -0
- package/dist/assets/yargs-locales/nn.json +44 -0
- package/dist/assets/yargs-locales/pirate.json +13 -0
- package/dist/assets/yargs-locales/pl.json +49 -0
- package/dist/assets/yargs-locales/pt.json +45 -0
- package/dist/assets/yargs-locales/pt_BR.json +48 -0
- package/dist/assets/yargs-locales/ru.json +51 -0
- package/dist/assets/yargs-locales/th.json +46 -0
- package/dist/assets/yargs-locales/tr.json +48 -0
- package/dist/assets/yargs-locales/uk_UA.json +51 -0
- package/dist/assets/yargs-locales/uz.json +52 -0
- package/dist/assets/yargs-locales/zh_CN.json +48 -0
- package/dist/assets/yargs-locales/zh_TW.json +51 -0
- package/dist/converter-d8O3xkdU.js +102 -0
- package/dist/devtools-CGNZQKFV.js +24 -0
- package/dist/index.js +8 -0
- package/dist/rolldown-runtime-CEAe2Uac.js +7 -0
- package/dist/schemas-CBsmCNpK.js +372 -0
- package/dist/start.js +2310 -0
- package/package.json +38 -31
- package/.oxlintrc.json +0 -5
- package/.prettierignore +0 -2
- package/.turbo/turbo-build.log +0 -1
- package/CONTRIBUTING.md +0 -45
- package/__test__/agent-auth.test.ts +0 -114
- package/__test__/agent-claim.test.ts +0 -164
- package/__test__/agent-credentials.test.ts +0 -149
- package/__test__/agent-deployment.test.ts +0 -106
- package/__test__/agent-setup-config.test.ts +0 -324
- package/__test__/agent-setup.test.ts +0 -207
- package/__test__/agent.test.ts +0 -64
- package/__test__/analytics/client.test.ts +0 -180
- package/__test__/analytics/dates.test.ts +0 -12
- package/__test__/analytics/filters.test.ts +0 -116
- package/__test__/analytics/format.test.ts +0 -137
- package/__test__/authenticatedFetch.test.ts +0 -182
- package/__test__/brokenLinks.test.ts +0 -283
- package/__test__/checkPort.test.ts +0 -92
- package/__test__/deploy-github-actions.test.ts +0 -202
- package/__test__/deploy-github-setup.test.ts +0 -240
- package/__test__/deploy-instructions.test.ts +0 -155
- package/__test__/deploy.test.ts +0 -202
- package/__test__/feedback.test.ts +0 -34
- package/__test__/foreignSyntax.test.ts +0 -73
- package/__test__/format.test.ts +0 -72
- package/__test__/helpers.test.ts +0 -52
- package/__test__/init.test.ts +0 -119
- package/__test__/instructions.test.ts +0 -53
- package/__test__/keyring.test.ts +0 -82
- package/__test__/mdxAccessibility.test.ts +0 -81
- package/__test__/migrate.test.ts +0 -186
- package/__test__/openApiCheck.test.ts +0 -185
- package/__test__/pathValidation.test.ts +0 -25
- package/__test__/resolveFiles.test.ts +0 -70
- package/__test__/sessionId.test.ts +0 -46
- package/__test__/signup.test.ts +0 -36
- package/__test__/update.test.ts +0 -117
- package/__test__/utils.ts +0 -25
- package/__test__/validateCommand.test.ts +0 -647
- package/__test__/validateEngine.test.ts +0 -245
- package/__test__/validateRules.test.ts +0 -1275
- package/__test__/welcome.test.ts +0 -15
- package/__test__/workflows/client.test.ts +0 -126
- package/bin/accessibility.js +0 -111
- package/bin/accessibilityCheck.js +0 -82
- package/bin/addDomain.js +0 -130
- package/bin/agent-auth.js +0 -104
- package/bin/agent-claim.js +0 -97
- package/bin/agent-credentials.js +0 -124
- package/bin/agent-deployment.js +0 -96
- package/bin/agent-http.js +0 -45
- package/bin/agent-setup-config.js +0 -141
- package/bin/agent-setup.js +0 -146
- package/bin/agent.js +0 -42
- package/bin/analytics/client.js +0 -60
- package/bin/analytics/dates.js +0 -6
- package/bin/analytics/filters.js +0 -27
- package/bin/analytics/format.js +0 -13
- package/bin/analytics/index.js +0 -496
- package/bin/analytics/output.js +0 -75
- package/bin/analytics/types.js +0 -1
- package/bin/authenticatedFetch.js +0 -46
- package/bin/brokenLinks.js +0 -122
- package/bin/callbackServer.js +0 -65
- package/bin/cli.js +0 -813
- package/bin/comingSoon.js +0 -26
- package/bin/config.js +0 -78
- package/bin/constants.js +0 -16
- package/bin/deploy-base.js +0 -20
- package/bin/deploy-github-actions.js +0 -102
- package/bin/deploy-github-setup.js +0 -165
- package/bin/deploy-instructions.js +0 -71
- package/bin/deploy.js +0 -123
- package/bin/feedback.js +0 -36
- package/bin/format.js +0 -121
- package/bin/helpers.js +0 -238
- package/bin/idToken.js +0 -14
- package/bin/index.js +0 -102
- package/bin/init.js +0 -182
- package/bin/instructions.js +0 -101
- package/bin/keyring.js +0 -78
- package/bin/login.js +0 -123
- package/bin/logout.js +0 -18
- package/bin/mdxAccessibility.js +0 -113
- package/bin/mdxLinter.js +0 -55
- package/bin/middlewares/subdomainMiddleware.js +0 -28
- package/bin/middlewares/telemetryMiddleware.js +0 -61
- package/bin/migrate.js +0 -54
- package/bin/og.js +0 -145
- package/bin/openApiCheck.js +0 -99
- package/bin/resolveFiles.js +0 -114
- package/bin/score/client.js +0 -40
- package/bin/score/index.js +0 -211
- package/bin/score/types.js +0 -1
- package/bin/signup.js +0 -118
- package/bin/start.js +0 -36
- package/bin/status.js +0 -106
- package/bin/telemetry/client.js +0 -53
- package/bin/telemetry/distinctId.js +0 -68
- package/bin/telemetry/sessionId.js +0 -36
- package/bin/telemetry/track.js +0 -149
- package/bin/templates.js +0 -127
- package/bin/tokenRefresh.js +0 -50
- package/bin/tsconfig.build.tsbuildinfo +0 -1
- package/bin/update.js +0 -65
- package/bin/validate/command.js +0 -127
- package/bin/validate/engine.js +0 -154
- package/bin/validate/files.js +0 -163
- package/bin/validate/mdx.js +0 -238
- package/bin/validate/output.js +0 -44
- package/bin/validate/report.js +0 -11
- package/bin/validate/rules/build.js +0 -102
- package/bin/validate/rules/content/duplicateH1.js +0 -57
- package/bin/validate/rules/content/foreignSyntax.js +0 -120
- package/bin/validate/rules/content/katex.js +0 -34
- package/bin/validate/rules/content/missingSnippet.js +0 -34
- package/bin/validate/rules/content/undefinedVariable.js +0 -13
- package/bin/validate/rules/content/unknownComponent.js +0 -121
- package/bin/validate/rules/content/voidTags.js +0 -38
- package/bin/validate/rules/index.js +0 -21
- package/bin/validate/rules/openapi.js +0 -50
- package/bin/validate/rules/parseError.js +0 -7
- package/bin/validate/site.js +0 -57
- package/bin/validate/types.js +0 -1
- package/bin/vendor/converter.js +0 -30882
- package/bin/welcome.js +0 -108
- package/bin/workflows/client.js +0 -34
- package/bin/workflows/index.js +0 -269
- package/bin/workflows/types.js +0 -11
- package/scripts/bundle-converter.mjs +0 -26
- package/scripts/generate-logo.mjs +0 -79
- package/src/accessibility.ts +0 -180
- package/src/accessibilityCheck.tsx +0 -150
- package/src/addDomain.tsx +0 -206
- package/src/agent-auth.ts +0 -119
- package/src/agent-claim.ts +0 -124
- package/src/agent-credentials.ts +0 -104
- package/src/agent-deployment.ts +0 -116
- package/src/agent-http.ts +0 -34
- package/src/agent-setup-config.ts +0 -144
- package/src/agent-setup.ts +0 -165
- package/src/agent.ts +0 -56
- package/src/analytics/client.ts +0 -153
- package/src/analytics/dates.ts +0 -6
- package/src/analytics/filters.ts +0 -50
- package/src/analytics/format.ts +0 -13
- package/src/analytics/index.tsx +0 -599
- package/src/analytics/output.ts +0 -99
- package/src/analytics/types.ts +0 -145
- package/src/authenticatedFetch.ts +0 -42
- package/src/brokenLinks.tsx +0 -152
- package/src/callbackServer.ts +0 -64
- package/src/cli.tsx +0 -1105
- package/src/comingSoon.tsx +0 -29
- package/src/config.ts +0 -75
- package/src/constants.ts +0 -28
- package/src/deploy-base.ts +0 -18
- package/src/deploy-github-actions.ts +0 -139
- package/src/deploy-github-setup.ts +0 -189
- package/src/deploy-instructions.ts +0 -76
- package/src/deploy.ts +0 -165
- package/src/feedback.tsx +0 -31
- package/src/format.tsx +0 -82
- package/src/helpers.tsx +0 -279
- package/src/idToken.ts +0 -17
- package/src/index.ts +0 -109
- package/src/init.tsx +0 -237
- package/src/instructions.ts +0 -99
- package/src/keyring.ts +0 -65
- package/src/login.tsx +0 -166
- package/src/logout.tsx +0 -8
- package/src/mdxAccessibility.ts +0 -134
- package/src/mdxLinter.tsx +0 -88
- package/src/middlewares/subdomainMiddleware.ts +0 -20
- package/src/middlewares/telemetryMiddleware.ts +0 -55
- package/src/migrate.ts +0 -76
- package/src/og.tsx +0 -185
- package/src/openApiCheck.tsx +0 -125
- package/src/resolveFiles.ts +0 -101
- package/src/score/client.ts +0 -36
- package/src/score/index.tsx +0 -205
- package/src/score/types.ts +0 -15
- package/src/signup.tsx +0 -172
- package/src/start.ts +0 -27
- package/src/status.tsx +0 -129
- package/src/telemetry/client.ts +0 -46
- package/src/telemetry/distinctId.ts +0 -70
- package/src/telemetry/sessionId.ts +0 -40
- package/src/telemetry/track.ts +0 -163
- package/src/templates.tsx +0 -143
- package/src/tokenRefresh.ts +0 -53
- package/src/update.tsx +0 -89
- package/src/validate/command.tsx +0 -135
- package/src/validate/engine.ts +0 -210
- package/src/validate/files.ts +0 -249
- package/src/validate/mdx.ts +0 -290
- package/src/validate/output.tsx +0 -76
- package/src/validate/report.ts +0 -40
- package/src/validate/rules/build.ts +0 -146
- package/src/validate/rules/content/duplicateH1.ts +0 -78
- package/src/validate/rules/content/foreignSyntax.ts +0 -144
- package/src/validate/rules/content/katex.ts +0 -33
- package/src/validate/rules/content/missingSnippet.ts +0 -36
- package/src/validate/rules/content/undefinedVariable.ts +0 -20
- package/src/validate/rules/content/unknownComponent.ts +0 -130
- package/src/validate/rules/content/voidTags.ts +0 -43
- package/src/validate/rules/index.ts +0 -23
- package/src/validate/rules/openapi.ts +0 -59
- package/src/validate/rules/parseError.ts +0 -9
- package/src/validate/site.ts +0 -53
- package/src/validate/types.ts +0 -102
- package/src/vendor/converter.ts +0 -1
- package/src/welcome.ts +0 -154
- package/src/workflows/client.ts +0 -39
- package/src/workflows/index.tsx +0 -287
- package/src/workflows/types.ts +0 -73
- package/tsconfig.build.json +0 -4
- package/tsconfig.json +0 -10
- package/vitest.config.ts +0 -9
package/src/validate/mdx.ts
DELETED
|
@@ -1,290 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
coreRemark,
|
|
3
|
-
FRONTMATTER_RE,
|
|
4
|
-
getCodeRanges,
|
|
5
|
-
HEADING_ID_RE,
|
|
6
|
-
JSXParser,
|
|
7
|
-
pagePathToSlug,
|
|
8
|
-
replaceSlashIndex,
|
|
9
|
-
safeCleanHeadingId,
|
|
10
|
-
toPosixPath,
|
|
11
|
-
} from '@mintlify/common';
|
|
12
|
-
import { decorateGraphNodeFromPageContent, Node, PathType } from '@mintlify/link-rot';
|
|
13
|
-
import type { Root } from 'mdast';
|
|
14
|
-
|
|
15
|
-
import type { Edit } from './types.js';
|
|
16
|
-
|
|
17
|
-
const HEADING_ID = new RegExp(HEADING_ID_RE.source, 'gm');
|
|
18
|
-
const ESM_START = /^(?:import|export)(?=[\s{*])/;
|
|
19
|
-
const JSX_TAG = /<[A-Za-z][\w.:-]*(?:"[^"]*"|'[^']*'|\{[^{}]*\}|[^<>"'{}])*>/g;
|
|
20
|
-
const ATTR_VALUE = /"[^"]*"|'[^']*'|\{[^{}]*\}/g;
|
|
21
|
-
|
|
22
|
-
export const hasCustomHeadingId = (line: string) => /\{\s*#[^}]+?\s*\}\s*$/.test(line);
|
|
23
|
-
|
|
24
|
-
export const parseContent = (content: string): Root => {
|
|
25
|
-
const padded = content.replace(
|
|
26
|
-
HEADING_ID,
|
|
27
|
-
(match, indent: string, hashes: string, text: string) => {
|
|
28
|
-
const end = match.indexOf(text, indent.length + hashes.length) + text.length;
|
|
29
|
-
return match.slice(0, end).padEnd(match.length, ' ');
|
|
30
|
-
}
|
|
31
|
-
);
|
|
32
|
-
return coreRemark().parse(padded);
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
type Range = [number, number];
|
|
36
|
-
|
|
37
|
-
const blankRanges = (content: string, ranges: Range[]) => {
|
|
38
|
-
let result = '';
|
|
39
|
-
let cursor = 0;
|
|
40
|
-
for (const [from, to] of [...ranges].sort((a, b) => a[0] - b[0])) {
|
|
41
|
-
const start = Math.max(from, cursor);
|
|
42
|
-
if (to <= start) continue;
|
|
43
|
-
result += content.slice(cursor, start) + content.slice(start, to).replace(/[^\n]/g, ' ');
|
|
44
|
-
cursor = to;
|
|
45
|
-
}
|
|
46
|
-
return result + content.slice(cursor);
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
const maskWith = (content: string, maskers: ((content: string) => Range[])[]) =>
|
|
50
|
-
maskers.reduce((text, ranges) => blankRanges(text, ranges(text)), content);
|
|
51
|
-
|
|
52
|
-
const isCompleteEsm = (text: string) => {
|
|
53
|
-
try {
|
|
54
|
-
JSXParser.parse(text, { ecmaVersion: 'latest', sourceType: 'module' });
|
|
55
|
-
return true;
|
|
56
|
-
} catch (error) {
|
|
57
|
-
const pos = (error as { pos?: unknown }).pos;
|
|
58
|
-
return typeof pos !== 'number' || pos < text.trimEnd().length;
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
const frontmatterRanges = (content: string): Range[] => {
|
|
63
|
-
const match = FRONTMATTER_RE.exec(content);
|
|
64
|
-
return match ? [[match.index, match.index + match[0].length]] : [];
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
const esmRanges = (content: string, codeRanges: Range[]): Range[] => {
|
|
68
|
-
let esm: string[] | undefined;
|
|
69
|
-
let previousBlank = true;
|
|
70
|
-
const ranges: Range[] = [];
|
|
71
|
-
let offset = 0;
|
|
72
|
-
for (const line of content.split('\n')) {
|
|
73
|
-
const isBlank = line.trim() === '';
|
|
74
|
-
const wasBlank = previousBlank;
|
|
75
|
-
previousBlank = isBlank;
|
|
76
|
-
if (esm) {
|
|
77
|
-
if (isBlank && isCompleteEsm(esm.join('\n'))) esm = undefined;
|
|
78
|
-
else {
|
|
79
|
-
esm.push(line);
|
|
80
|
-
ranges.push([offset, offset + line.length]);
|
|
81
|
-
}
|
|
82
|
-
} else if (
|
|
83
|
-
wasBlank &&
|
|
84
|
-
ESM_START.test(line) &&
|
|
85
|
-
!codeRanges.some(([start, end]) => start <= offset && offset < end)
|
|
86
|
-
) {
|
|
87
|
-
esm = [line];
|
|
88
|
-
ranges.push([offset, offset + line.length]);
|
|
89
|
-
}
|
|
90
|
-
offset += line.length + 1;
|
|
91
|
-
}
|
|
92
|
-
return ranges;
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
export const maskFrontmatter = (content: string): string =>
|
|
96
|
-
blankRanges(content, frontmatterRanges(content));
|
|
97
|
-
|
|
98
|
-
export const maskCode = (content: string, { keepEsm = false } = {}): string => {
|
|
99
|
-
const codeRanges = getCodeRanges(content);
|
|
100
|
-
return blankRanges(content, [
|
|
101
|
-
...frontmatterRanges(content),
|
|
102
|
-
...codeRanges,
|
|
103
|
-
...(keepEsm ? [] : esmRanges(content, codeRanges)),
|
|
104
|
-
]);
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
const OPENS = new Set(['{', '${']);
|
|
108
|
-
|
|
109
|
-
const maskExpression = (content: string, start: number): { ranges: Range[]; end: number } => {
|
|
110
|
-
const ranges: Range[] = [];
|
|
111
|
-
let depth = 0;
|
|
112
|
-
try {
|
|
113
|
-
const tokens = JSXParser.tokenizer(content.slice(start), {
|
|
114
|
-
ecmaVersion: 'latest',
|
|
115
|
-
onComment: (block, _text, from, to) =>
|
|
116
|
-
ranges.push([start + from + 2, start + to - (block ? 2 : 0)]),
|
|
117
|
-
});
|
|
118
|
-
for (const token of tokens) {
|
|
119
|
-
const label = token.type.label;
|
|
120
|
-
if (label === 'template') ranges.push([start + token.start, start + token.end]);
|
|
121
|
-
else if (label === 'string') ranges.push([start + token.start + 1, start + token.end - 1]);
|
|
122
|
-
else if (label === 'regexp') {
|
|
123
|
-
const raw = content.slice(start + token.start, start + token.end);
|
|
124
|
-
ranges.push([start + token.start + 1, start + token.start + raw.lastIndexOf('/')]);
|
|
125
|
-
} else if (OPENS.has(label)) depth++;
|
|
126
|
-
else if (label === '}' && depth-- === 0) return { ranges, end: start + token.end };
|
|
127
|
-
}
|
|
128
|
-
} catch (error) {
|
|
129
|
-
if (!(error instanceof SyntaxError && 'pos' in error && typeof error.pos === 'number')) {
|
|
130
|
-
return { ranges, end: content.length };
|
|
131
|
-
}
|
|
132
|
-
const pos = start + error.pos;
|
|
133
|
-
if (!error.message.startsWith('Unterminated string')) return { ranges, end: pos };
|
|
134
|
-
const lineEnd = content.indexOf('\n', pos);
|
|
135
|
-
ranges.push([pos + 1, lineEnd === -1 ? content.length : lineEnd]);
|
|
136
|
-
}
|
|
137
|
-
return { ranges, end: content.length };
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
const expressionRanges = (content: string): Range[] => {
|
|
141
|
-
const ranges: Range[] = [];
|
|
142
|
-
for (let index = 0; index < content.length; index++) {
|
|
143
|
-
const char = content[index];
|
|
144
|
-
if (char === '\\') index++;
|
|
145
|
-
else if (char === '{') {
|
|
146
|
-
const expression = maskExpression(content, index + 1);
|
|
147
|
-
ranges.push(...expression.ranges);
|
|
148
|
-
index = expression.end - 1;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
return ranges;
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
const attributeRanges = (content: string): Range[] =>
|
|
155
|
-
[...content.matchAll(JSX_TAG)].flatMap(({ index, 0: tag }) =>
|
|
156
|
-
[...tag.matchAll(ATTR_VALUE)].map(
|
|
157
|
-
({ index: at, 0: value }): Range => [index + at + 1, index + at + value.length - 1]
|
|
158
|
-
)
|
|
159
|
-
);
|
|
160
|
-
|
|
161
|
-
const escapedTagRanges = (content: string): Range[] =>
|
|
162
|
-
[...content.matchAll(/\\[\s\S]/g)].flatMap(({ index, 0: escape }): Range[] =>
|
|
163
|
-
escape === '\\<' ? [[index + 1, index + 2]] : []
|
|
164
|
-
);
|
|
165
|
-
|
|
166
|
-
export const maskNonMarkup = (content: string): string =>
|
|
167
|
-
maskWith(maskCode(content), [attributeRanges, escapedTagRanges, expressionRanges]);
|
|
168
|
-
|
|
169
|
-
export const selectEdits = <T extends Edit>(edits: T[]): T[] => {
|
|
170
|
-
const ordered = edits
|
|
171
|
-
.map((edit, index) => ({ edit, index }))
|
|
172
|
-
.sort((a, b) => b.edit.start - a.edit.start || b.edit.end - a.edit.end || b.index - a.index);
|
|
173
|
-
const selected: T[] = [];
|
|
174
|
-
let floor = Infinity;
|
|
175
|
-
for (const { edit } of ordered) {
|
|
176
|
-
if (edit.end > floor) continue;
|
|
177
|
-
selected.push(edit);
|
|
178
|
-
floor = edit.start;
|
|
179
|
-
}
|
|
180
|
-
return selected;
|
|
181
|
-
};
|
|
182
|
-
|
|
183
|
-
export const applyEdits = (content: string, edits: Edit[]): string =>
|
|
184
|
-
selectEdits(edits).reduce(
|
|
185
|
-
(result, edit) => result.slice(0, edit.start) + edit.text + result.slice(edit.end),
|
|
186
|
-
content
|
|
187
|
-
);
|
|
188
|
-
|
|
189
|
-
export const toOffset = (content: string, line: number, column = 1) => {
|
|
190
|
-
let offset = 0;
|
|
191
|
-
for (let current = 1; current < line; current++) {
|
|
192
|
-
const next = content.indexOf('\n', offset);
|
|
193
|
-
if (next === -1) break;
|
|
194
|
-
offset = next + 1;
|
|
195
|
-
}
|
|
196
|
-
return offset + column - 1;
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
export const toPosition = (content: string, offset: number) => {
|
|
200
|
-
const before = content.slice(0, offset).split('\n');
|
|
201
|
-
return { line: before.length, column: (before.pop()?.length ?? 0) + 1 };
|
|
202
|
-
};
|
|
203
|
-
|
|
204
|
-
const byStart = (a: Edit, b: Edit) => a.start - b.start;
|
|
205
|
-
|
|
206
|
-
/** Maps an offset in edited content back to the content before the edits, or undefined inside an edit. */
|
|
207
|
-
function toOriginal(edits: Edit[], offset: number, inside: 'snap'): number;
|
|
208
|
-
function toOriginal(edits: Edit[], offset: number, inside: 'reject'): number | undefined;
|
|
209
|
-
function toOriginal(edits: Edit[], offset: number, inside: 'snap' | 'reject') {
|
|
210
|
-
let delta = 0;
|
|
211
|
-
for (const edit of edits) {
|
|
212
|
-
const start = edit.start + delta;
|
|
213
|
-
if (inside === 'snap' ? offset < start : offset <= start) break;
|
|
214
|
-
if (offset < start + edit.text.length) return inside === 'snap' ? edit.start : undefined;
|
|
215
|
-
delta += edit.text.length - (edit.end - edit.start);
|
|
216
|
-
}
|
|
217
|
-
return offset - delta;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
/** Maps an edit made against a later stage back to the original content, or undefined when it touches an earlier fix. */
|
|
221
|
-
export const unmapEdit = (
|
|
222
|
-
stages: { content: string; edits: Edit[] }[],
|
|
223
|
-
index: number,
|
|
224
|
-
edit: Edit
|
|
225
|
-
): Edit | undefined => {
|
|
226
|
-
let { start, end } = edit;
|
|
227
|
-
for (const { edits } of stages.slice(0, index).reverse()) {
|
|
228
|
-
const sorted = [...edits].sort(byStart);
|
|
229
|
-
const mappedStart = toOriginal(sorted, start, 'reject');
|
|
230
|
-
const mappedEnd = toOriginal(sorted, end, 'reject');
|
|
231
|
-
if (mappedStart === undefined || mappedEnd === undefined) return undefined;
|
|
232
|
-
if (sorted.some((earlier) => earlier.start < mappedEnd && earlier.end > mappedStart)) {
|
|
233
|
-
return undefined;
|
|
234
|
-
}
|
|
235
|
-
start = mappedStart;
|
|
236
|
-
end = mappedEnd;
|
|
237
|
-
}
|
|
238
|
-
return { start, end, text: edit.text };
|
|
239
|
-
};
|
|
240
|
-
|
|
241
|
-
export const relocate = (
|
|
242
|
-
stages: { content: string; edits: Edit[] }[],
|
|
243
|
-
index: number,
|
|
244
|
-
position: { line?: number; column?: number }
|
|
245
|
-
) => {
|
|
246
|
-
const stage = stages[index];
|
|
247
|
-
const original = stages[0];
|
|
248
|
-
if (!stage || !original || position.line === undefined) return {};
|
|
249
|
-
const offset = stages
|
|
250
|
-
.slice(0, index)
|
|
251
|
-
.reduceRight(
|
|
252
|
-
(current, { edits }) => toOriginal([...edits].sort(byStart), current, 'snap'),
|
|
253
|
-
toOffset(stage.content, position.line, position.column)
|
|
254
|
-
);
|
|
255
|
-
const mapped = toPosition(original.content, offset);
|
|
256
|
-
return position.column === undefined ? { line: mapped.line } : mapped;
|
|
257
|
-
};
|
|
258
|
-
|
|
259
|
-
const pagePath = (file: string) => replaceSlashIndex(pagePathToSlug(file)).replace(/^\.$/, '');
|
|
260
|
-
|
|
261
|
-
export const collectAnchorLinks = async (file: string, content: string): Promise<string[]> => {
|
|
262
|
-
const node = new Node(file);
|
|
263
|
-
try {
|
|
264
|
-
await decorateGraphNodeFromPageContent(node, content);
|
|
265
|
-
} catch {
|
|
266
|
-
return [];
|
|
267
|
-
}
|
|
268
|
-
return node.paths.flatMap((link) =>
|
|
269
|
-
link.pathType === PathType.INTERNAL && link.anchorLink
|
|
270
|
-
? [
|
|
271
|
-
`${pagePath(toPosixPath(link.toString()))}#${safeCleanHeadingId(link.anchorLink.slice(1))}`,
|
|
272
|
-
]
|
|
273
|
-
: []
|
|
274
|
-
);
|
|
275
|
-
};
|
|
276
|
-
|
|
277
|
-
export const linkedAnchor = (
|
|
278
|
-
links: ReadonlySet<string> | undefined,
|
|
279
|
-
file: string,
|
|
280
|
-
slug: string
|
|
281
|
-
): string | undefined => {
|
|
282
|
-
const prefix = `${pagePath(file)}#`;
|
|
283
|
-
for (const link of links ?? []) {
|
|
284
|
-
if (!link.startsWith(prefix)) continue;
|
|
285
|
-
const anchor = link.slice(prefix.length);
|
|
286
|
-
const suffix = anchor.startsWith(`${slug}-`) && /^\d/.test(anchor.slice(slug.length + 1));
|
|
287
|
-
if (anchor === slug || suffix) return anchor;
|
|
288
|
-
}
|
|
289
|
-
return undefined;
|
|
290
|
-
};
|
package/src/validate/output.tsx
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { addLog, ErrorLog, InfoLog, SuccessLog } from '@mintlify/previewing';
|
|
2
|
-
import { Box, Text } from 'ink';
|
|
3
|
-
|
|
4
|
-
import type { Report } from './report.js';
|
|
5
|
-
import type { Diagnostic } from './types.js';
|
|
6
|
-
|
|
7
|
-
const preview = (value: string) => {
|
|
8
|
-
const text = JSON.stringify(value);
|
|
9
|
-
return text.length > 60 ? `${text.slice(0, 57)}..."` : text;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
const location = ({ line, column }: Pick<Diagnostic, 'line' | 'column'>) =>
|
|
13
|
-
line ? `${line}${column ? `:${column}` : ''}` : '';
|
|
14
|
-
|
|
15
|
-
const DiagnosticLine = ({ diagnostic }: { diagnostic: Diagnostic }) => {
|
|
16
|
-
const at = location(diagnostic);
|
|
17
|
-
return (
|
|
18
|
-
<Text>
|
|
19
|
-
{' '}
|
|
20
|
-
{diagnostic.severity === 'error' ? (
|
|
21
|
-
<Text color="red">✗</Text>
|
|
22
|
-
) : (
|
|
23
|
-
<Text color="yellow">!</Text>
|
|
24
|
-
)}{' '}
|
|
25
|
-
{at && <Text dimColor>{at} </Text>}
|
|
26
|
-
<Text dimColor>{diagnostic.rule}</Text> {diagnostic.message}
|
|
27
|
-
{diagnostic.fix && <Text dimColor> (fixable)</Text>}
|
|
28
|
-
</Text>
|
|
29
|
-
);
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
const plural = (count: number, word: string) => `${count} ${word}${count === 1 ? '' : 's'}`;
|
|
33
|
-
|
|
34
|
-
export const logReport = (report: Report) => {
|
|
35
|
-
for (const change of report.fixed ?? []) {
|
|
36
|
-
addLog(
|
|
37
|
-
<SuccessLog
|
|
38
|
-
message={`fixed ${change.file}${change.line ? `:${change.line}` : ''} ${change.rule}: ${preview(change.before)} → ${preview(change.after)}`}
|
|
39
|
-
/>
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const byFile = new Map<string, Diagnostic[]>();
|
|
44
|
-
for (const diagnostic of report.diagnostics) {
|
|
45
|
-
byFile.get(diagnostic.file)?.push(diagnostic) ?? byFile.set(diagnostic.file, [diagnostic]);
|
|
46
|
-
}
|
|
47
|
-
for (const [file, diagnostics] of byFile) {
|
|
48
|
-
addLog(
|
|
49
|
-
<Box flexDirection="column">
|
|
50
|
-
<Text bold>{file}</Text>
|
|
51
|
-
{diagnostics.map((diagnostic, index) => (
|
|
52
|
-
<DiagnosticLine key={index} diagnostic={diagnostic} />
|
|
53
|
-
))}
|
|
54
|
-
</Box>
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const fixable = report.diagnostics.filter(({ fix }) => fix).length;
|
|
59
|
-
if (fixable > 0 && !report.fixed) {
|
|
60
|
-
addLog(<InfoLog message={`\`--fix\` would fix ${plural(fixable, 'issue')}.`} />);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const { build } = report;
|
|
64
|
-
if (build.ran && build.passed) addLog(<SuccessLog message="build passed" />);
|
|
65
|
-
else if (build.ran && report.passed)
|
|
66
|
-
addLog(<InfoLog message="build failed only on disabled rules" />);
|
|
67
|
-
else if (build.ran) addLog(<ErrorLog message="build failed" />);
|
|
68
|
-
else if (build.reason === 'errors found')
|
|
69
|
-
addLog(<InfoLog message="build skipped until the errors above are fixed" />);
|
|
70
|
-
|
|
71
|
-
const { errors, warnings } = report.summary;
|
|
72
|
-
const warned = plural(warnings, 'warning');
|
|
73
|
-
const passed = warnings > 0 ? `passed with ${warned}` : 'validation passed';
|
|
74
|
-
const failed = `${plural(errors, 'error')}${warnings > 0 ? `, ${warned}` : ''}`;
|
|
75
|
-
addLog(report.passed ? <SuccessLog message={passed} /> : <ErrorLog message={failed} />);
|
|
76
|
-
};
|
package/src/validate/report.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import type { Change, Diagnostic } from './types.js';
|
|
2
|
-
|
|
3
|
-
export type BuildStatus =
|
|
4
|
-
| { ran: true; passed: boolean }
|
|
5
|
-
| { ran: false; reason: 'disabled' | 'errors found' | 'no build rules' };
|
|
6
|
-
|
|
7
|
-
export type Report = {
|
|
8
|
-
passed: boolean;
|
|
9
|
-
summary: { errors: number; warnings: number; byRule: Record<string, number> };
|
|
10
|
-
diagnostics: Diagnostic[];
|
|
11
|
-
build: BuildStatus;
|
|
12
|
-
/** With --fix: the edits that were applied. */
|
|
13
|
-
fixed?: Change[];
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export const toReport = (
|
|
17
|
-
diagnostics: Diagnostic[],
|
|
18
|
-
build: BuildStatus,
|
|
19
|
-
fixed?: Change[]
|
|
20
|
-
): Report => {
|
|
21
|
-
const byRule: Record<string, number> = {};
|
|
22
|
-
for (const { rule } of diagnostics) byRule[rule] = (byRule[rule] ?? 0) + 1;
|
|
23
|
-
const errors = diagnostics.filter(({ severity }) => severity === 'error').length;
|
|
24
|
-
return {
|
|
25
|
-
passed: errors === 0,
|
|
26
|
-
summary: { errors, warnings: diagnostics.length - errors, byRule },
|
|
27
|
-
diagnostics: diagnostics.map(({ rule, group, severity, file, line, column, message, fix }) => ({
|
|
28
|
-
rule,
|
|
29
|
-
group,
|
|
30
|
-
severity,
|
|
31
|
-
file,
|
|
32
|
-
...(line !== undefined && { line }),
|
|
33
|
-
...(column !== undefined && { column }),
|
|
34
|
-
message,
|
|
35
|
-
...(fix && { fix }),
|
|
36
|
-
})),
|
|
37
|
-
build,
|
|
38
|
-
...(fixed && { fixed }),
|
|
39
|
-
};
|
|
40
|
-
};
|
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
import { normalizeRelativePath, toPosixPath } from '@mintlify/common';
|
|
2
|
-
import type { Warning } from '@mintlify/prebuild';
|
|
3
|
-
import { stripVTControlCharacters } from 'node:util';
|
|
4
|
-
|
|
5
|
-
import type { Finding, Group, Site, SiteRule } from '../types.js';
|
|
6
|
-
|
|
7
|
-
const FILE = String.raw`[\w@.\\/-]+\.(?:mdx?|jsx?|tsx?|json|ya?ml)\b`;
|
|
8
|
-
|
|
9
|
-
const FILE_IN_MESSAGE = new RegExp(FILE);
|
|
10
|
-
|
|
11
|
-
const IMPORTERS = [
|
|
12
|
-
new RegExp(String.raw`\(in (${FILE}),`),
|
|
13
|
-
new RegExp(String.raw`(?:\bin|imported from) (${FILE})`),
|
|
14
|
-
];
|
|
15
|
-
|
|
16
|
-
const IMPORT_TYPES = new Set<Warning['type']>([
|
|
17
|
-
'missing-file',
|
|
18
|
-
'invalid-import-path',
|
|
19
|
-
'import-resolution-error',
|
|
20
|
-
'default-import-no-default-export',
|
|
21
|
-
'export-collision',
|
|
22
|
-
'undeclared-package',
|
|
23
|
-
'package-import-conflict',
|
|
24
|
-
]);
|
|
25
|
-
|
|
26
|
-
const POSITION = /^:(\d+)(?::(\d+))?/;
|
|
27
|
-
|
|
28
|
-
const QUOTED = /"([^"]+)"/;
|
|
29
|
-
|
|
30
|
-
const toFinding = (site: Site, warning: Warning): Finding => {
|
|
31
|
-
const clean = stripVTControlCharacters(warning.message).trim();
|
|
32
|
-
const importer =
|
|
33
|
-
warning.file == null && IMPORT_TYPES.has(warning.type)
|
|
34
|
-
? IMPORTERS.map((pattern) => pattern.exec(clean)?.[1]).find(Boolean)
|
|
35
|
-
: undefined;
|
|
36
|
-
// Missing nav pages are always about the config, even when the page looks like a file
|
|
37
|
-
const match =
|
|
38
|
-
warning.file != null || importer || warning.type === 'missing-nav-page'
|
|
39
|
-
? null
|
|
40
|
-
: FILE_IN_MESSAGE.exec(clean);
|
|
41
|
-
const found = importer ?? match?.[0];
|
|
42
|
-
const file =
|
|
43
|
-
warning.file ?? (found ? normalizeRelativePath(toPosixPath(found)) : site.configFile);
|
|
44
|
-
const position = match ? POSITION.exec(clean.slice(match.index + match[0].length)) : null;
|
|
45
|
-
// Config warnings quote the entry they're about, such as a navigation page
|
|
46
|
-
const quoted =
|
|
47
|
-
warning.file == null && file === site.configFile ? QUOTED.exec(clean)?.[0] : undefined;
|
|
48
|
-
const located =
|
|
49
|
-
warning.ref != null && warning.line == null
|
|
50
|
-
? site.locate(file, JSON.stringify(warning.ref))
|
|
51
|
-
: quoted
|
|
52
|
-
? site.locate(file, quoted)
|
|
53
|
-
: undefined;
|
|
54
|
-
return {
|
|
55
|
-
file,
|
|
56
|
-
...(warning.line != null
|
|
57
|
-
? { line: warning.line, ...(warning.column != null && { column: warning.column }) }
|
|
58
|
-
: position && {
|
|
59
|
-
line: Number(position[1]),
|
|
60
|
-
...(position[2] && { column: Number(position[2]) }),
|
|
61
|
-
}),
|
|
62
|
-
...located,
|
|
63
|
-
message: clean,
|
|
64
|
-
};
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
/** Warning types some rule turns into diagnostics, so a strict-build failure is explained. */
|
|
68
|
-
const COVERED_TYPES = new Set<Warning['type']>(['parse-error']);
|
|
69
|
-
|
|
70
|
-
const buildRule = (
|
|
71
|
-
id: string,
|
|
72
|
-
group: Group,
|
|
73
|
-
types: Warning['type'][],
|
|
74
|
-
description: string
|
|
75
|
-
): SiteRule => {
|
|
76
|
-
for (const type of types) COVERED_TYPES.add(type);
|
|
77
|
-
return {
|
|
78
|
-
id,
|
|
79
|
-
group,
|
|
80
|
-
severity: 'error',
|
|
81
|
-
needsBuild: true,
|
|
82
|
-
scope: 'site',
|
|
83
|
-
description,
|
|
84
|
-
check: (site) =>
|
|
85
|
-
(site.build?.warnings ?? [])
|
|
86
|
-
.filter(({ type }) => types.includes(type))
|
|
87
|
-
.map((warning) => toFinding(site, warning)),
|
|
88
|
-
};
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
export const BUILD_RULES: SiteRule[] = [
|
|
92
|
-
buildRule(
|
|
93
|
-
'missing-nav-page',
|
|
94
|
-
'nav',
|
|
95
|
-
['missing-nav-page'],
|
|
96
|
-
'pages in the navigation that have no file'
|
|
97
|
-
),
|
|
98
|
-
buildRule('missing-file', 'content', ['missing-file'], "imported files that don't exist"),
|
|
99
|
-
buildRule(
|
|
100
|
-
'import-error',
|
|
101
|
-
'content',
|
|
102
|
-
[
|
|
103
|
-
'invalid-import-path',
|
|
104
|
-
'import-resolution-error',
|
|
105
|
-
'default-import-no-default-export',
|
|
106
|
-
'export-collision',
|
|
107
|
-
],
|
|
108
|
-
"imports in pages and snippets that don't resolve"
|
|
109
|
-
),
|
|
110
|
-
buildRule(
|
|
111
|
-
'package-import',
|
|
112
|
-
'config',
|
|
113
|
-
['undeclared-package', 'package-import-conflict'],
|
|
114
|
-
'npm package imports that are undeclared or conflict'
|
|
115
|
-
),
|
|
116
|
-
buildRule('openapi-build', 'openapi', ['openapi'], 'OpenAPI pages the build could not generate'),
|
|
117
|
-
{
|
|
118
|
-
id: 'build-failed',
|
|
119
|
-
group: 'config',
|
|
120
|
-
severity: 'error',
|
|
121
|
-
needsBuild: true,
|
|
122
|
-
scope: 'site',
|
|
123
|
-
description: 'the strict build failed for a reason no rule reports',
|
|
124
|
-
check: (site) => {
|
|
125
|
-
if (!site.build || site.build.passed) return [];
|
|
126
|
-
const unreported = (warning: Warning) =>
|
|
127
|
-
warning.type === 'parse-error' &&
|
|
128
|
-
site.selected !== undefined &&
|
|
129
|
-
!site.selected.has(toFinding(site, warning).file);
|
|
130
|
-
const uncovered = site.build.warnings.filter(
|
|
131
|
-
(warning) => !COVERED_TYPES.has(warning.type) || unreported(warning)
|
|
132
|
-
);
|
|
133
|
-
const findings = uncovered.map((warning) => toFinding(site, warning));
|
|
134
|
-
// Covered warnings are the selected rules' to report; disabled ones are meant to pass
|
|
135
|
-
return site.build.strict
|
|
136
|
-
? findings
|
|
137
|
-
: [...findings, { file: site.configFile, message: site.build.error }];
|
|
138
|
-
},
|
|
139
|
-
},
|
|
140
|
-
];
|
|
141
|
-
|
|
142
|
-
/** Build warnings of one type, which the engine merges into the static rule that covers them. */
|
|
143
|
-
export const buildFindings = (site: Site, type: Warning['type']): Finding[] =>
|
|
144
|
-
(site.build?.warnings ?? [])
|
|
145
|
-
.filter((warning) => warning.type === type)
|
|
146
|
-
.map((warning) => toFinding(site, warning));
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
AVOIDED_PAGE_MODES,
|
|
3
|
-
getTableOfContentsTitle,
|
|
4
|
-
safeCleanHeadingId,
|
|
5
|
-
slugify,
|
|
6
|
-
} from '@mintlify/common';
|
|
7
|
-
import type { Heading, Root } from 'mdast';
|
|
8
|
-
import remarkSmartypants from 'remark-smartypants';
|
|
9
|
-
import { unified } from 'unified';
|
|
10
|
-
|
|
11
|
-
import { hasCustomHeadingId, linkedAnchor } from '../../mdx.js';
|
|
12
|
-
import type { FileRule } from '../../types.js';
|
|
13
|
-
|
|
14
|
-
const normalize = (value: string) => value.trim().replace(/\s+/g, ' ');
|
|
15
|
-
|
|
16
|
-
const smartypants = unified().use(remarkSmartypants);
|
|
17
|
-
|
|
18
|
-
const firstHeading = (tree: Root) =>
|
|
19
|
-
tree.children.find((node): node is Heading => node.type === 'heading');
|
|
20
|
-
|
|
21
|
-
const renderedText = (heading: Heading) => {
|
|
22
|
-
const clone = structuredClone(heading);
|
|
23
|
-
const root: Root = { type: 'root', children: [clone] };
|
|
24
|
-
smartypants.runSync(root);
|
|
25
|
-
return getTableOfContentsTitle(clone);
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export const duplicateH1: FileRule = {
|
|
29
|
-
id: 'duplicate-h1',
|
|
30
|
-
group: 'content',
|
|
31
|
-
severity: 'warning',
|
|
32
|
-
scope: 'file',
|
|
33
|
-
description: 'remove a first heading that repeats the frontmatter title',
|
|
34
|
-
pagesOnly: true,
|
|
35
|
-
needsAnchorLinks: true,
|
|
36
|
-
check: ({ tree, frontmatter, content, file, anchorLinks }) => {
|
|
37
|
-
const { title, mode } = frontmatter;
|
|
38
|
-
if (typeof title !== 'string' || AVOIDED_PAGE_MODES.includes(String(mode))) return [];
|
|
39
|
-
const first = firstHeading(tree);
|
|
40
|
-
if (!first || first.depth !== 1) return [];
|
|
41
|
-
if (normalize(getTableOfContentsTitle(first)) !== normalize(title)) return [];
|
|
42
|
-
const start = first.position?.start.offset ?? 0;
|
|
43
|
-
const end = first.position?.end.offset ?? start;
|
|
44
|
-
const location = {
|
|
45
|
-
line: first.position?.start.line,
|
|
46
|
-
column: first.position?.start.column,
|
|
47
|
-
};
|
|
48
|
-
const lineEnd = content.indexOf('\n', start);
|
|
49
|
-
if (hasCustomHeadingId(content.slice(start, lineEnd === -1 ? undefined : lineEnd))) {
|
|
50
|
-
return [
|
|
51
|
-
{
|
|
52
|
-
...location,
|
|
53
|
-
message:
|
|
54
|
-
'first heading duplicates the frontmatter title; it has a custom {#id}, so remove it by hand and update links to it',
|
|
55
|
-
},
|
|
56
|
-
];
|
|
57
|
-
}
|
|
58
|
-
const anchor = [renderedText(first), getTableOfContentsTitle(first)]
|
|
59
|
-
.map((text) => linkedAnchor(anchorLinks, file, safeCleanHeadingId(slugify(text))))
|
|
60
|
-
.find((linked) => linked !== undefined);
|
|
61
|
-
if (anchor !== undefined) {
|
|
62
|
-
return [
|
|
63
|
-
{
|
|
64
|
-
...location,
|
|
65
|
-
message: `first heading duplicates the frontmatter title; links point to #${anchor}, so remove it by hand and update them`,
|
|
66
|
-
},
|
|
67
|
-
];
|
|
68
|
-
}
|
|
69
|
-
const trailing = /^\n*/.exec(content.slice(end))?.[0].length ?? 0;
|
|
70
|
-
return [
|
|
71
|
-
{
|
|
72
|
-
...location,
|
|
73
|
-
message: 'first heading duplicates the frontmatter title',
|
|
74
|
-
edit: { start, end: end + trailing, text: '' },
|
|
75
|
-
},
|
|
76
|
-
];
|
|
77
|
-
},
|
|
78
|
-
};
|