@mintlify/link-rot 3.0.903 → 3.0.905
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.
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { TableOfContentsSectionType } from '@mintlify/common';
|
|
2
|
+
import type { Root } from 'mdast';
|
|
2
3
|
import { Node } from '../graph.js';
|
|
3
4
|
export declare const flattenTableOfContentsSlugs: (sections: TableOfContentsSectionType[]) => Set<string>;
|
|
5
|
+
export declare const extractComponentAnchorIds: (tree: Root) => Set<string>;
|
|
4
6
|
export declare const decorateGraphNodeFromPageContent: (graphNode: Node, content: string) => Promise<void>;
|
|
5
7
|
/**
|
|
6
8
|
* 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 { cleanHeadingId, coreRemark, isMintIgnored, remarkComponentIds, remarkExtractTableOfContents, } from '@mintlify/common';
|
|
10
|
+
import { cleanHeadingId, coreRemark, generateParamFieldId, 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';
|
|
@@ -27,6 +27,38 @@ export const flattenTableOfContentsSlugs = (sections) => {
|
|
|
27
27
|
}
|
|
28
28
|
return slugs;
|
|
29
29
|
};
|
|
30
|
+
const PARAM_FIELD_NAMES = new Set(['ParamField', 'Param', 'ResponseField']);
|
|
31
|
+
const PARAM_FIELD_ATTR_NAMES = new Set(['query', 'path', 'body', 'header', 'name']);
|
|
32
|
+
export const extractComponentAnchorIds = (tree) => {
|
|
33
|
+
const ids = new Set();
|
|
34
|
+
const paramCounts = new Map();
|
|
35
|
+
visit(tree, 'mdxJsxFlowElement', (node) => {
|
|
36
|
+
var _a, _b;
|
|
37
|
+
if (node.name === 'Heading') {
|
|
38
|
+
const idAttr = node.attributes.find((attr) => 'name' in attr && attr.name === 'id');
|
|
39
|
+
if (idAttr && typeof idAttr.value === 'string') {
|
|
40
|
+
ids.add(cleanHeadingId(idAttr.value));
|
|
41
|
+
}
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (PARAM_FIELD_NAMES.has((_a = node.name) !== null && _a !== void 0 ? _a : '')) {
|
|
45
|
+
const nameAttr = node.attributes.find((attr) => 'name' in attr && PARAM_FIELD_ATTR_NAMES.has(attr.name));
|
|
46
|
+
if (nameAttr && typeof nameAttr.value === 'string' && nameAttr.value) {
|
|
47
|
+
const currentCount = (_b = paramCounts.get(nameAttr.value)) !== null && _b !== void 0 ? _b : 0;
|
|
48
|
+
paramCounts.set(nameAttr.value, currentCount + 1);
|
|
49
|
+
ids.add(generateParamFieldId(nameAttr.value, currentCount));
|
|
50
|
+
}
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (node.name === 'Accordion') {
|
|
54
|
+
const idAttr = node.attributes.find((attr) => 'name' in attr && attr.name === 'id');
|
|
55
|
+
if (idAttr && typeof idAttr.value === 'string' && idAttr.value) {
|
|
56
|
+
ids.add(idAttr.value);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
return ids;
|
|
61
|
+
};
|
|
30
62
|
export const decorateGraphNodeFromPageContent = (graphNode, content) => __awaiter(void 0, void 0, void 0, function* () {
|
|
31
63
|
const mdxExtracts = {};
|
|
32
64
|
const visitLinks = () => {
|
|
@@ -67,9 +99,11 @@ export const decorateGraphNodeFromPageContent = (graphNode, content) => __awaite
|
|
|
67
99
|
.use(remarkExtractTableOfContents, mdxExtracts);
|
|
68
100
|
const tree = processor.parse(content);
|
|
69
101
|
yield processor.run(tree);
|
|
70
|
-
|
|
102
|
+
const tocSlugs = mdxExtracts.tableOfContents
|
|
71
103
|
? flattenTableOfContentsSlugs(mdxExtracts.tableOfContents)
|
|
72
104
|
: new Set();
|
|
105
|
+
const componentIds = extractComponentAnchorIds(tree);
|
|
106
|
+
graphNode.headingSlugs = new Set([...tocSlugs, ...componentIds]);
|
|
73
107
|
});
|
|
74
108
|
/**
|
|
75
109
|
* Get all broken internal links used in the site
|