@mintlify/link-rot 3.0.576 → 3.0.577
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/graph.d.ts
CHANGED
|
@@ -65,9 +65,14 @@ export declare class Graph {
|
|
|
65
65
|
private nodes;
|
|
66
66
|
private edges;
|
|
67
67
|
private fileResolutionMap;
|
|
68
|
+
private redirectMap;
|
|
68
69
|
constructor(baseDir: string);
|
|
69
70
|
addNode(label: string): Node;
|
|
70
71
|
addNodes(labels: string[]): void;
|
|
72
|
+
setRedirects(redirects: {
|
|
73
|
+
source: string;
|
|
74
|
+
destination: string;
|
|
75
|
+
}[]): void;
|
|
71
76
|
addAliasNodes(): void;
|
|
72
77
|
getNode(label: string): Node | undefined;
|
|
73
78
|
private addEdge;
|
package/dist/graph.js
CHANGED
|
@@ -212,6 +212,7 @@ export class Graph {
|
|
|
212
212
|
this.nodes = {};
|
|
213
213
|
this.edges = [];
|
|
214
214
|
this.fileResolutionMap = new Map();
|
|
215
|
+
this.redirectMap = new Map();
|
|
215
216
|
this.baseDir = resolve(baseDir);
|
|
216
217
|
}
|
|
217
218
|
addNode(label) {
|
|
@@ -225,6 +226,11 @@ export class Graph {
|
|
|
225
226
|
this.addNode(label);
|
|
226
227
|
}
|
|
227
228
|
}
|
|
229
|
+
setRedirects(redirects) {
|
|
230
|
+
for (const redirect of redirects) {
|
|
231
|
+
this.redirectMap.set(normalizePath(redirect.source), normalizePath(redirect.destination));
|
|
232
|
+
}
|
|
233
|
+
}
|
|
228
234
|
/*
|
|
229
235
|
* Aliases are additional paths that are valid due to redirects
|
|
230
236
|
*/
|
|
@@ -287,8 +293,12 @@ export class Graph {
|
|
|
287
293
|
for (const node of Object.values(this.nodes)) {
|
|
288
294
|
for (const path of node.paths) {
|
|
289
295
|
if (path.pathType === PathType.INTERNAL) {
|
|
290
|
-
const
|
|
291
|
-
|
|
296
|
+
const pathString = path.toString();
|
|
297
|
+
const resolvedFiles = this.fileResolutionMap.get(pathString);
|
|
298
|
+
const hasExistingFile = resolvedFiles && [...resolvedFiles].some((file) => nodeSet.has(file));
|
|
299
|
+
const redirectDestination = this.redirectMap.get(pathString);
|
|
300
|
+
const hasValidRedirect = redirectDestination && nodeSet.has(`${redirectDestination}.mdx`);
|
|
301
|
+
if (!hasExistingFile && !hasValidRedirect) {
|
|
292
302
|
brokenLinks.push(path);
|
|
293
303
|
}
|
|
294
304
|
}
|
|
@@ -13,6 +13,7 @@ import path from 'path';
|
|
|
13
13
|
import { visit } from 'unist-util-visit';
|
|
14
14
|
import { Graph, Wrapper } from '../graph.js';
|
|
15
15
|
import { getLinkPaths, getPagePaths } from '../prebuild.js';
|
|
16
|
+
import { getRedirects } from './getRedirects.js';
|
|
16
17
|
export const decorateGraphNodeFromPageContent = (graphNode, content) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
18
|
const visitLinks = () => {
|
|
18
19
|
return (tree) => {
|
|
@@ -58,6 +59,9 @@ export const getBrokenInternalLinks = (repoPath) => __awaiter(void 0, void 0, vo
|
|
|
58
59
|
// add nodes for every page or media path in project
|
|
59
60
|
const filenames = getLinkPaths(baseDir);
|
|
60
61
|
graph.addNodes(filenames);
|
|
62
|
+
// pull redirects from docs.json or mint.json if either exist
|
|
63
|
+
const redirectMappings = yield getRedirects(baseDir);
|
|
64
|
+
graph.setRedirects(redirectMappings);
|
|
61
65
|
// add nodes for every link alias in the project
|
|
62
66
|
graph.addAliasNodes();
|
|
63
67
|
const sitePages = getPagePaths(baseDir);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { validateDocsConfig, validateMintConfig } from '@mintlify/validation';
|
|
11
|
+
import fs from 'fs-extra';
|
|
12
|
+
import path from 'path';
|
|
13
|
+
export const getRedirects = (baseDir) => __awaiter(void 0, void 0, void 0, function* () {
|
|
14
|
+
const configRedirects = [];
|
|
15
|
+
// read docs.json or mint.json to get redirects
|
|
16
|
+
if (fs.existsSync(path.join(baseDir, 'docs.json'))) {
|
|
17
|
+
const docsJson = yield fs.readFile(path.join(baseDir, 'docs.json'), 'utf8');
|
|
18
|
+
const result = validateDocsConfig(docsJson);
|
|
19
|
+
if (result.success && 'redirects' in result.data && result.data.redirects) {
|
|
20
|
+
configRedirects.push(...result.data.redirects);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
else if (fs.existsSync(path.join(baseDir, 'mint.json'))) {
|
|
24
|
+
const mintJson = yield fs.readFile(path.join(baseDir, 'mint.json'), 'utf8');
|
|
25
|
+
const result = validateMintConfig(mintJson);
|
|
26
|
+
if (result.success && 'redirects' in result.data && result.data.redirects) {
|
|
27
|
+
configRedirects.push(...result.data.redirects);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return configRedirects;
|
|
31
|
+
});
|