@mintlify/link-rot 3.0.1608 → 3.0.1610

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
@@ -10,7 +10,8 @@ export declare enum Wrapper {
10
10
  SRC = "src",// <img src="" />
11
11
  HREF = "href",// <a href="" />
12
12
  CARD = "card",// <Card to="" />
13
- IMPORT = "import"
13
+ IMPORT = "import",
14
+ DEFINITION = "definition"
14
15
  }
15
16
  export declare enum EdgeType {
16
17
  CONTENT = "content",
@@ -38,6 +39,7 @@ export declare class MdxPath {
38
39
  constructor(originalPath: string, relativeDir?: string, filename?: string, wrapper?: Wrapper | undefined, line?: number | undefined);
39
40
  toString(): string;
40
41
  getResolvedFiles(fileIndex: FileIndex, baseDir: string): string[];
42
+ keepsMdxExtension(): boolean;
41
43
  resolvesTo(node: Node, fileIndex: FileIndex, baseDir: string): boolean;
42
44
  static filterMapInternalPaths(paths: string[]): string[];
43
45
  }
@@ -114,6 +116,7 @@ export declare class Graph {
114
116
  private getPageCandidates;
115
117
  private isPageRoute;
116
118
  private resolvesToValidPath;
119
+ private redirectsToPage;
117
120
  private reachesPage;
118
121
  private getExactRedirectTarget;
119
122
  private getRedirectTarget;
package/dist/graph.js CHANGED
@@ -1,4 +1,4 @@
1
- import { isMintIgnored, safeCleanHeadingId } from '@mintlify/common';
1
+ import { isMintIgnored, resolveRelativeUrl, safeCleanHeadingId } from '@mintlify/common';
2
2
  import { getFileListWithDirectories } from '@mintlify/prebuild';
3
3
  import { existsSync } from 'fs';
4
4
  import { parse, join, resolve, dirname, basename } from 'path';
@@ -28,6 +28,7 @@ export var Wrapper;
28
28
  Wrapper["HREF"] = "href";
29
29
  Wrapper["CARD"] = "card";
30
30
  Wrapper["IMPORT"] = "import";
31
+ Wrapper["DEFINITION"] = "definition";
31
32
  })(Wrapper || (Wrapper = {}));
32
33
  export var EdgeType;
33
34
  (function (EdgeType) {
@@ -125,6 +126,14 @@ export class MdxPath {
125
126
  resolvedFiles.push(...fileIndex.lookup(dir, name, base));
126
127
  return resolvedFiles;
127
128
  }
129
+ keepsMdxExtension() {
130
+ const renderedUrl = this.wrapper === Wrapper.DEFINITION
131
+ ? this.originalPath
132
+ : this.wrapper === Wrapper.MD || this.wrapper === Wrapper.HREF
133
+ ? resolveRelativeUrl(join(this.relativeDir, this.filename), this.originalPath, true)
134
+ : undefined;
135
+ return renderedUrl !== undefined && /\.mdx$/i.test(removeSelectors(renderedUrl));
136
+ }
128
137
  resolvesTo(node, fileIndex, baseDir) {
129
138
  if (this.pathType !== PathType.INTERNAL)
130
139
  return false;
@@ -440,7 +449,8 @@ export class Graph {
440
449
  const hasExistingFile = isSiteRoot ||
441
450
  (resolvedFiles && [...resolvedFiles].some((file) => nodeSet.has(file))) ||
442
451
  this.virtualNodes.has(pathString);
443
- if (!hasExistingFile && !this.reachesPage(pathString)) {
452
+ if ((path.keepsMdxExtension() && !this.redirectsToPage(pathString)) ||
453
+ (!hasExistingFile && !this.reachesPage(pathString))) {
444
454
  brokenLinks.add(path);
445
455
  }
446
456
  else if ((options === null || options === void 0 ? void 0 : options.checkAnchors) && path.anchorLink) {
@@ -506,6 +516,10 @@ export class Graph {
506
516
  return true;
507
517
  return this.reachesPage(normalizePath(pathOnly), visited);
508
518
  }
519
+ redirectsToPage(normalized) {
520
+ const redirected = this.getRedirectTarget(normalized);
521
+ return redirected !== undefined && this.resolvesToValidPath(redirected, new Set([normalized]));
522
+ }
509
523
  reachesPage(normalized, visited = new Set()) {
510
524
  if (visited.has(normalized))
511
525
  return false;
@@ -92,8 +92,9 @@ export const decorateGraphNodeFromPageContent = (graphNode, content, options) =>
92
92
  return;
93
93
  }
94
94
  if (node.type === 'definition') {
95
- if (referenced.delete(node.identifier))
96
- graphNode.addPath(node.url, Wrapper.MD, line);
95
+ if (referenced.delete(node.identifier)) {
96
+ graphNode.addPath(node.url, Wrapper.DEFINITION, line);
97
+ }
97
98
  return;
98
99
  }
99
100
  const mdxJsxFlowElement = node;