@mintlify/link-rot 3.0.892 → 3.0.893

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
@@ -43,6 +43,7 @@ export declare class Node {
43
43
  relativeDir: string;
44
44
  filename: string;
45
45
  edges: Edge[];
46
+ headingSlugs: Set<string> | null;
46
47
  constructor(label: string, paths?: MdxPath[]);
47
48
  toString(): string;
48
49
  equals(other: Node): boolean;
@@ -83,6 +84,7 @@ export declare class Graph {
83
84
  private addEdge;
84
85
  addEdgesBetweenNodes(): void;
85
86
  precomputeFileResolutions(): void;
87
+ private getHeadingSlugsForPath;
86
88
  getBrokenInternalLinks(): MdxPath[];
87
89
  getAllInternalPaths(): string[];
88
90
  }
package/dist/graph.js CHANGED
@@ -150,6 +150,7 @@ export class Node {
150
150
  this.label = label;
151
151
  this.paths = paths;
152
152
  this.edges = [];
153
+ this.headingSlugs = null;
153
154
  this.relativeDir = normalizePath(dirname(label));
154
155
  this.filename = basename(label);
155
156
  this.label = join(this.relativeDir, this.filename);
@@ -339,6 +340,22 @@ export class Graph {
339
340
  });
340
341
  });
341
342
  }
343
+ getHeadingSlugsForPath(pathString, nodeSet) {
344
+ const resolvedFiles = this.fileResolutionMap.get(pathString);
345
+ if (resolvedFiles) {
346
+ for (const file of resolvedFiles) {
347
+ if (nodeSet.has(file)) {
348
+ const node = this.nodes[file];
349
+ if (node && node.headingSlugs !== null)
350
+ return node.headingSlugs;
351
+ }
352
+ }
353
+ }
354
+ const directNode = this.nodes[pathString];
355
+ if (directNode && directNode.headingSlugs !== null)
356
+ return directNode.headingSlugs;
357
+ return undefined;
358
+ }
342
359
  getBrokenInternalLinks() {
343
360
  if (this.fileResolutionMap.size === 0) {
344
361
  this.precomputeFileResolutions();
@@ -369,6 +386,13 @@ export class Graph {
369
386
  if (!hasExistingFile && !hasValidRedirect) {
370
387
  brokenLinks.push(path);
371
388
  }
389
+ else if (path.anchorLink) {
390
+ const anchor = path.anchorLink.slice(1);
391
+ const headingSlugs = this.getHeadingSlugsForPath(pathString, nodeSet);
392
+ if (headingSlugs && !headingSlugs.has(anchor)) {
393
+ brokenLinks.push(path);
394
+ }
395
+ }
372
396
  }
373
397
  }
374
398
  }
@@ -1,4 +1,6 @@
1
+ import type { TableOfContentsSectionType } from '@mintlify/common';
1
2
  import { Node } from '../graph.js';
3
+ export declare const flattenTableOfContentsSlugs: (sections: TableOfContentsSectionType[]) => Set<string>;
2
4
  export declare const decorateGraphNodeFromPageContent: (graphNode: Node, content: string) => Promise<void>;
3
5
  /**
4
6
  * Get all broken internal links used in the site
@@ -7,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import { coreRemark, isMintIgnored } from '@mintlify/common';
10
+ import { coreRemark, isMintIgnored, remarkComponentIds, remarkExtractTableOfContents, } from '@mintlify/common';
11
11
  import { getMintIgnore } from '@mintlify/prebuild';
12
12
  import fs from 'fs-extra';
13
13
  import path from 'path';
@@ -16,7 +16,18 @@ import { Graph, Wrapper } from '../graph.js';
16
16
  import { getLinkPaths, getPagePaths } from '../prebuild.js';
17
17
  import { getOpenApiPagePaths } from './getOpenApiPagePaths.js';
18
18
  import { getRedirects } from './getRedirects.js';
19
+ export const flattenTableOfContentsSlugs = (sections) => {
20
+ const slugs = new Set();
21
+ for (const section of sections) {
22
+ slugs.add(section.slug);
23
+ for (const slug of flattenTableOfContentsSlugs(section.children)) {
24
+ slugs.add(slug);
25
+ }
26
+ }
27
+ return slugs;
28
+ };
19
29
  export const decorateGraphNodeFromPageContent = (graphNode, content) => __awaiter(void 0, void 0, void 0, function* () {
30
+ const mdxExtracts = {};
20
31
  const visitLinks = () => {
21
32
  return (tree) => {
22
33
  visit(tree, (node) => {
@@ -49,8 +60,15 @@ export const decorateGraphNodeFromPageContent = (graphNode, content) => __awaite
49
60
  return tree;
50
61
  };
51
62
  };
52
- yield coreRemark().use(visitLinks).process(content);
53
- return;
63
+ const processor = coreRemark()
64
+ .use(visitLinks)
65
+ .use(remarkComponentIds)
66
+ .use(remarkExtractTableOfContents, mdxExtracts);
67
+ const tree = processor.parse(content);
68
+ yield processor.run(tree);
69
+ graphNode.headingSlugs = mdxExtracts.tableOfContents
70
+ ? flattenTableOfContentsSlugs(mdxExtracts.tableOfContents)
71
+ : new Set();
54
72
  });
55
73
  /**
56
74
  * Get all broken internal links used in the site