@mintlify/scraping 4.0.5 → 4.0.6
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/bin/components/AccordionGroup.d.ts +3 -3
- package/bin/components/AccordionGroup.js +54 -27
- package/bin/components/AccordionGroup.js.map +1 -1
- package/bin/components/Card.js +3 -2
- package/bin/components/Card.js.map +1 -1
- package/bin/components/CardGroup.js +3 -6
- package/bin/components/CardGroup.js.map +1 -1
- package/bin/components/CodeGroup.d.ts +1 -1
- package/bin/components/CodeGroup.js +107 -79
- package/bin/components/CodeGroup.js.map +1 -1
- package/bin/components/Tabs.d.ts +1 -1
- package/bin/components/Tabs.js +50 -23
- package/bin/components/Tabs.js.map +1 -1
- package/bin/constants.js +3 -3
- package/bin/constants.js.map +1 -1
- package/bin/nav/listItems.js +0 -1
- package/bin/nav/listItems.js.map +1 -1
- package/bin/scrapingPipeline/color.d.ts +8 -0
- package/bin/scrapingPipeline/color.js +91 -0
- package/bin/scrapingPipeline/color.js.map +1 -0
- package/bin/scrapingPipeline/group.js +1 -3
- package/bin/scrapingPipeline/group.js.map +1 -1
- package/bin/scrapingPipeline/icon.d.ts +1 -1
- package/bin/scrapingPipeline/icon.js +7 -6
- package/bin/scrapingPipeline/icon.js.map +1 -1
- package/bin/scrapingPipeline/logo.js +13 -9
- package/bin/scrapingPipeline/logo.js.map +1 -1
- package/bin/scrapingPipeline/page.js +28 -9
- package/bin/scrapingPipeline/page.js.map +1 -1
- package/bin/scrapingPipeline/site.js +64 -7
- package/bin/scrapingPipeline/site.js.map +1 -1
- package/bin/scrapingPipeline/tabs.js +15 -10
- package/bin/scrapingPipeline/tabs.js.map +1 -1
- package/bin/scrapingPipeline/title.d.ts +2 -0
- package/bin/scrapingPipeline/title.js +34 -0
- package/bin/scrapingPipeline/title.js.map +1 -0
- package/bin/tabs/retrieveReadme.js +0 -1
- package/bin/tabs/retrieveReadme.js.map +1 -1
- package/bin/tsconfig.build.tsbuildinfo +1 -1
- package/bin/types/result.d.ts +1 -0
- package/bin/utils/breaks.d.ts +3 -0
- package/bin/utils/breaks.js +17 -0
- package/bin/utils/breaks.js.map +1 -0
- package/bin/utils/children.js +9 -3
- package/bin/utils/children.js.map +1 -1
- package/bin/utils/className.d.ts +0 -1
- package/bin/utils/className.js +1 -1
- package/bin/utils/className.js.map +1 -1
- package/bin/utils/copyButton.d.ts +3 -0
- package/bin/utils/copyButton.js +30 -0
- package/bin/utils/copyButton.js.map +1 -0
- package/bin/utils/emptyEmphasis.d.ts +2 -0
- package/bin/utils/emptyEmphasis.js +18 -0
- package/bin/utils/emptyEmphasis.js.map +1 -0
- package/bin/utils/emptyParagraphs.d.ts +0 -1
- package/bin/utils/emptyParagraphs.js +1 -1
- package/bin/utils/emptyParagraphs.js.map +1 -1
- package/bin/utils/formatEmphasis.d.ts +2 -0
- package/bin/utils/formatEmphasis.js +32 -0
- package/bin/utils/formatEmphasis.js.map +1 -0
- package/bin/utils/images.js +9 -1
- package/bin/utils/images.js.map +1 -1
- package/bin/utils/lists.d.ts +2 -0
- package/bin/utils/lists.js +21 -0
- package/bin/utils/lists.js.map +1 -0
- package/bin/utils/log.d.ts +17 -0
- package/bin/utils/log.js +15 -5
- package/bin/utils/log.js.map +1 -1
- package/bin/utils/metadata.d.ts +2 -0
- package/bin/utils/metadata.js +23 -0
- package/bin/utils/metadata.js.map +1 -0
- package/bin/utils/nestedRoots.d.ts +0 -1
- package/bin/utils/nestedRoots.js +1 -1
- package/bin/utils/nestedRoots.js.map +1 -1
- package/bin/utils/position.d.ts +0 -1
- package/bin/utils/position.js +1 -1
- package/bin/utils/position.js.map +1 -1
- package/bin/utils/tableCells.d.ts +2 -0
- package/bin/utils/tableCells.js +22 -0
- package/bin/utils/tableCells.js.map +1 -0
- package/bin/utils/title.d.ts +1 -0
- package/bin/utils/title.js +9 -3
- package/bin/utils/title.js.map +1 -1
- package/bin/utils/updatedAt.d.ts +2 -0
- package/bin/utils/updatedAt.js +21 -0
- package/bin/utils/updatedAt.js.map +1 -0
- package/package.json +2 -2
- package/src/components/AccordionGroup.ts +55 -25
- package/src/components/Card.ts +3 -2
- package/src/components/CardGroup.ts +3 -6
- package/src/components/CodeGroup.ts +127 -83
- package/src/components/Tabs.ts +57 -24
- package/src/constants.ts +3 -3
- package/src/nav/listItems.ts +1 -2
- package/src/scrapingPipeline/color.ts +107 -0
- package/src/scrapingPipeline/group.ts +1 -4
- package/src/scrapingPipeline/icon.ts +8 -6
- package/src/scrapingPipeline/logo.ts +14 -9
- package/src/scrapingPipeline/page.ts +30 -9
- package/src/scrapingPipeline/site.ts +83 -7
- package/src/scrapingPipeline/tabs.ts +15 -13
- package/src/scrapingPipeline/title.ts +38 -0
- package/src/tabs/retrieveReadme.ts +1 -2
- package/src/types/result.ts +1 -1
- package/src/utils/breaks.ts +19 -0
- package/src/utils/children.ts +10 -3
- package/src/utils/className.ts +1 -1
- package/src/utils/copyButton.ts +35 -0
- package/src/utils/emptyEmphasis.ts +18 -0
- package/src/utils/emptyParagraphs.ts +1 -1
- package/src/utils/formatEmphasis.ts +37 -0
- package/src/utils/images.ts +13 -2
- package/src/utils/lists.ts +22 -0
- package/src/utils/log.ts +18 -5
- package/src/utils/metadata.ts +26 -0
- package/src/utils/nestedRoots.ts +1 -1
- package/src/utils/position.ts +1 -1
- package/src/utils/tableCells.ts +23 -0
- package/src/utils/title.ts +10 -4
- package/src/utils/updatedAt.ts +25 -0
- package/bin/utils/escape.d.ts +0 -2
- package/bin/utils/escape.js +0 -25
- package/bin/utils/escape.js.map +0 -1
- package/src/utils/escape.ts +0 -30
|
@@ -1,24 +1,34 @@
|
|
|
1
|
-
import type { Element } from 'hast';
|
|
1
|
+
import type { Element, ElementContent } from 'hast';
|
|
2
2
|
|
|
3
3
|
import type { HastNode, HastNodeIndex, HastNodeParent } from '../types/hast.js';
|
|
4
4
|
|
|
5
5
|
export function gitBookScrapeAccordionGroup(
|
|
6
6
|
node: HastNode,
|
|
7
|
-
|
|
7
|
+
index: HastNodeIndex,
|
|
8
8
|
parent: HastNodeParent
|
|
9
9
|
): Element | undefined {
|
|
10
10
|
if (node.tagName !== 'Accordion') return undefined;
|
|
11
|
-
|
|
12
|
-
if (!parent || !parent.children) return undefined;
|
|
11
|
+
if (!parent || typeof index !== 'number') return undefined;
|
|
13
12
|
|
|
14
13
|
let accordionCount = 0;
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
while (parent.children[index]) {
|
|
15
|
+
const child = parent.children[index];
|
|
16
|
+
if (!child || child.type !== 'element' || child.tagName !== 'Accordion') break;
|
|
17
|
+
accordionCount++;
|
|
18
|
+
index++;
|
|
17
19
|
}
|
|
18
20
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
index -= accordionCount;
|
|
22
|
+
|
|
23
|
+
if (accordionCount > 1) {
|
|
24
|
+
const children = parent.children.splice(index, accordionCount);
|
|
25
|
+
const newNode = {
|
|
26
|
+
type: 'element' as const,
|
|
27
|
+
tagName: 'AccordionGroup',
|
|
28
|
+
properties: {},
|
|
29
|
+
children: children as Array<ElementContent>,
|
|
30
|
+
};
|
|
31
|
+
parent.children.splice(index, 0, newNode);
|
|
22
32
|
}
|
|
23
33
|
|
|
24
34
|
return undefined;
|
|
@@ -26,21 +36,31 @@ export function gitBookScrapeAccordionGroup(
|
|
|
26
36
|
|
|
27
37
|
export function readmeScrapeAccordionGroup(
|
|
28
38
|
node: HastNode,
|
|
29
|
-
|
|
39
|
+
index: HastNodeIndex,
|
|
30
40
|
parent: HastNodeParent
|
|
31
41
|
): Element | undefined {
|
|
32
42
|
if (node.tagName !== 'Accordion') return undefined;
|
|
33
|
-
|
|
34
|
-
if (!parent || !parent.children) return undefined;
|
|
43
|
+
if (!parent || typeof index !== 'number') return undefined;
|
|
35
44
|
|
|
36
45
|
let accordionCount = 0;
|
|
37
|
-
|
|
38
|
-
|
|
46
|
+
while (parent.children[index]) {
|
|
47
|
+
const child = parent.children[index];
|
|
48
|
+
if (!child || child.type !== 'element' || child.tagName !== 'Accordion') break;
|
|
49
|
+
accordionCount++;
|
|
50
|
+
index++;
|
|
39
51
|
}
|
|
40
52
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
53
|
+
index -= accordionCount;
|
|
54
|
+
|
|
55
|
+
if (accordionCount > 1) {
|
|
56
|
+
const children = parent.children.splice(index, accordionCount);
|
|
57
|
+
const newNode = {
|
|
58
|
+
type: 'element' as const,
|
|
59
|
+
tagName: 'AccordionGroup',
|
|
60
|
+
properties: {},
|
|
61
|
+
children: children as Array<ElementContent>,
|
|
62
|
+
};
|
|
63
|
+
parent.children.splice(index, 0, newNode);
|
|
44
64
|
}
|
|
45
65
|
|
|
46
66
|
return undefined;
|
|
@@ -48,21 +68,31 @@ export function readmeScrapeAccordionGroup(
|
|
|
48
68
|
|
|
49
69
|
export function docusaurusScrapeAccordionGroup(
|
|
50
70
|
node: HastNode,
|
|
51
|
-
|
|
71
|
+
index: HastNodeIndex,
|
|
52
72
|
parent: HastNodeParent
|
|
53
73
|
): Element | undefined {
|
|
54
74
|
if (node.tagName !== 'Accordion') return undefined;
|
|
55
|
-
|
|
56
|
-
if (!parent || !parent.children) return undefined;
|
|
75
|
+
if (!parent || typeof index !== 'number') return undefined;
|
|
57
76
|
|
|
58
77
|
let accordionCount = 0;
|
|
59
|
-
|
|
60
|
-
|
|
78
|
+
while (parent.children[index]) {
|
|
79
|
+
const child = parent.children[index];
|
|
80
|
+
if (!child || child.type !== 'element' || child.tagName !== 'Accordion') break;
|
|
81
|
+
accordionCount++;
|
|
82
|
+
index++;
|
|
61
83
|
}
|
|
62
84
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
85
|
+
index -= accordionCount;
|
|
86
|
+
|
|
87
|
+
if (accordionCount > 1) {
|
|
88
|
+
const children = parent.children.splice(index, accordionCount);
|
|
89
|
+
const newNode = {
|
|
90
|
+
type: 'element' as const,
|
|
91
|
+
tagName: 'AccordionGroup',
|
|
92
|
+
properties: {},
|
|
93
|
+
children: children as Array<ElementContent>,
|
|
94
|
+
};
|
|
95
|
+
parent.children.splice(index, 0, newNode);
|
|
66
96
|
}
|
|
67
97
|
|
|
68
98
|
return undefined;
|
package/src/components/Card.ts
CHANGED
|
@@ -72,6 +72,7 @@ export function readmeScrapeCard(
|
|
|
72
72
|
!node.properties.className.includes('card') &&
|
|
73
73
|
!node.properties.className.includes('Card') &&
|
|
74
74
|
!node.properties.className.includes('docs-card') &&
|
|
75
|
+
!node.properties.className.includes('next-steps__step') &&
|
|
75
76
|
!node.properties.className.join(' ').includes('_card') &&
|
|
76
77
|
!node.properties.className.join(' ').includes('-card'))
|
|
77
78
|
) {
|
|
@@ -107,7 +108,7 @@ export function readmeScrapeCard(
|
|
|
107
108
|
title: title,
|
|
108
109
|
href: href,
|
|
109
110
|
},
|
|
110
|
-
children: turnChildrenIntoMdx(
|
|
111
|
+
children: turnChildrenIntoMdx(node.children as Array<Element>) as Array<ElementContent>,
|
|
111
112
|
};
|
|
112
113
|
|
|
113
114
|
return newNode;
|
|
@@ -161,7 +162,7 @@ export function docusaurusScrapeCard(
|
|
|
161
162
|
title: title,
|
|
162
163
|
href: href,
|
|
163
164
|
},
|
|
164
|
-
children: turnChildrenIntoMdx(
|
|
165
|
+
children: turnChildrenIntoMdx(node.children as Array<Element>) as Array<ElementContent>,
|
|
165
166
|
};
|
|
166
167
|
|
|
167
168
|
return newNode;
|
|
@@ -8,8 +8,7 @@ export function gitBookScrapeCardGroup(
|
|
|
8
8
|
parent: HastNodeParent
|
|
9
9
|
): Element | undefined {
|
|
10
10
|
if (node.tagName !== 'Card') return undefined;
|
|
11
|
-
|
|
12
|
-
if (!parent || !parent.children) return undefined;
|
|
11
|
+
if (!parent) return undefined;
|
|
13
12
|
|
|
14
13
|
let cardCount = 0;
|
|
15
14
|
for (const child of parent.children) {
|
|
@@ -30,8 +29,7 @@ export function readmeScrapeCardGroup(
|
|
|
30
29
|
parent: HastNodeParent
|
|
31
30
|
): Element | undefined {
|
|
32
31
|
if (node.tagName !== 'Card') return undefined;
|
|
33
|
-
|
|
34
|
-
if (!parent || !parent.children) return undefined;
|
|
32
|
+
if (!parent) return undefined;
|
|
35
33
|
|
|
36
34
|
let cardCount = 0;
|
|
37
35
|
for (const child of parent.children) {
|
|
@@ -52,8 +50,7 @@ export function docusaurusScrapeCardGroup(
|
|
|
52
50
|
parent: HastNodeParent
|
|
53
51
|
): Element | undefined {
|
|
54
52
|
if (node.tagName !== 'Card') return undefined;
|
|
55
|
-
|
|
56
|
-
if (!parent || !parent.children) return undefined;
|
|
53
|
+
if (!parent) return undefined;
|
|
57
54
|
|
|
58
55
|
let cardCount = 0;
|
|
59
56
|
for (const child of parent.children) {
|
|
@@ -6,36 +6,30 @@ import { assertIsDefined } from '../assert.js';
|
|
|
6
6
|
import type { HastNode, HastNodeIndex, HastNodeParent } from '../types/hast.js';
|
|
7
7
|
import { turnChildrenIntoMdx } from '../utils/children.js';
|
|
8
8
|
|
|
9
|
-
function tabContainsOnlyCode(node: Element): boolean {
|
|
9
|
+
function tabContainsOnlyCode(node: Element | undefined): boolean {
|
|
10
|
+
if (!node) return false;
|
|
11
|
+
|
|
10
12
|
let tabsCount = 0;
|
|
11
13
|
let onlyCodeCount = 0;
|
|
12
14
|
|
|
13
15
|
visit(node, 'element', function (subNode) {
|
|
14
|
-
if (subNode.properties.role
|
|
15
|
-
|
|
16
|
-
if (tabNode.tagName === 'button' && typeof index === 'number' && parent) {
|
|
17
|
-
parent.children.splice(index, 1);
|
|
18
|
-
}
|
|
19
|
-
});
|
|
16
|
+
if (subNode.properties.role !== 'tabpanel') return CONTINUE;
|
|
17
|
+
tabsCount++;
|
|
20
18
|
if (
|
|
21
19
|
subNode.children[0] &&
|
|
22
|
-
subNode.children[1] &&
|
|
23
|
-
subNode.children[2] &&
|
|
24
20
|
subNode.children[0].type === 'element' &&
|
|
25
21
|
subNode.children[0].children.length === 1 &&
|
|
26
|
-
subNode.children[
|
|
27
|
-
subNode.children[
|
|
28
|
-
subNode.children[
|
|
29
|
-
subNode.children[
|
|
30
|
-
subNode.children[2].children.length < 4 &&
|
|
31
|
-
subNode.children[2].children.find(
|
|
22
|
+
subNode.children[0].children[0] &&
|
|
23
|
+
subNode.children[0].children[0].type === 'element' &&
|
|
24
|
+
subNode.children[0].children[0].children.length > 1 &&
|
|
25
|
+
subNode.children[0].children[0].children.find(
|
|
32
26
|
(child) => child.type === 'element' && (child.tagName === 'pre' || child.tagName === 'code')
|
|
33
|
-
)
|
|
27
|
+
) !== undefined
|
|
34
28
|
) {
|
|
35
|
-
|
|
29
|
+
onlyCodeCount++;
|
|
36
30
|
}
|
|
37
31
|
});
|
|
38
|
-
return onlyCodeCount === tabsCount;
|
|
32
|
+
return onlyCodeCount === tabsCount && tabsCount > 0;
|
|
39
33
|
}
|
|
40
34
|
|
|
41
35
|
export function gitBookScrapeCodeGroup(
|
|
@@ -43,11 +37,46 @@ export function gitBookScrapeCodeGroup(
|
|
|
43
37
|
_: HastNodeIndex,
|
|
44
38
|
parent: HastNodeParent
|
|
45
39
|
): Element | undefined {
|
|
46
|
-
if (
|
|
47
|
-
|
|
40
|
+
if (
|
|
41
|
+
node.tagName === 'div' &&
|
|
42
|
+
Array.isArray(node.properties.className) &&
|
|
43
|
+
node.properties.className.includes('group/codeblock') &&
|
|
44
|
+
node.children.length === 2 &&
|
|
45
|
+
node.children[0] &&
|
|
46
|
+
node.children[1] &&
|
|
47
|
+
node.children[1].type === 'element' &&
|
|
48
|
+
(node.children[1].tagName === 'pre' || node.children[1].tagName === 'code')
|
|
49
|
+
) {
|
|
50
|
+
let title = '';
|
|
51
|
+
visit(node.children[0], 'text', function (subNode) {
|
|
52
|
+
title = subNode.value;
|
|
53
|
+
return EXIT;
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
if (!title) return undefined;
|
|
57
|
+
|
|
58
|
+
const children = turnChildrenIntoMdx([node.children[1]]);
|
|
59
|
+
const code = {
|
|
60
|
+
type: 'code',
|
|
61
|
+
lang: 'bash',
|
|
62
|
+
meta: title,
|
|
63
|
+
value: (children[0] as unknown as Code).value,
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const newNode: Element = {
|
|
67
|
+
type: 'element',
|
|
68
|
+
tagName: 'CodeGroup',
|
|
69
|
+
properties: {},
|
|
70
|
+
children: [code] as Array<ElementContent>,
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
return newNode;
|
|
48
74
|
}
|
|
49
75
|
|
|
50
|
-
if (
|
|
76
|
+
if (node.tagName !== 'div' || node.properties.role !== 'tablist') return undefined;
|
|
77
|
+
|
|
78
|
+
if (!tabContainsOnlyCode(parent as Element | undefined)) return undefined;
|
|
79
|
+
assertIsDefined(parent);
|
|
51
80
|
|
|
52
81
|
const titles: Array<string> = [];
|
|
53
82
|
visit(node, 'element', function (subNode) {
|
|
@@ -58,28 +87,31 @@ export function gitBookScrapeCodeGroup(
|
|
|
58
87
|
});
|
|
59
88
|
});
|
|
60
89
|
|
|
61
|
-
assertIsDefined(parent);
|
|
62
90
|
parent.children.shift();
|
|
63
91
|
|
|
64
|
-
|
|
65
|
-
visit(
|
|
66
|
-
if (
|
|
67
|
-
|
|
68
|
-
|
|
92
|
+
const langs: Array<string> = [];
|
|
93
|
+
visit(parent, 'element', function (subNode) {
|
|
94
|
+
if (
|
|
95
|
+
subNode.tagName === 'div' &&
|
|
96
|
+
'id' in subNode.properties &&
|
|
97
|
+
subNode.properties.role === 'tabpanel'
|
|
98
|
+
) {
|
|
99
|
+
langs.push(subNode.properties.id as string);
|
|
69
100
|
}
|
|
70
101
|
});
|
|
71
102
|
|
|
72
103
|
const children = turnChildrenIntoMdx(parent.children) as Array<ElementContent>;
|
|
73
104
|
const tabChildren: Array<ElementContent> = [];
|
|
74
|
-
|
|
75
|
-
const
|
|
105
|
+
children.forEach((child, index) => {
|
|
106
|
+
const lang = langs[index] || 'bash';
|
|
107
|
+
const title = titles[index] || lang;
|
|
76
108
|
tabChildren.push({
|
|
77
109
|
type: 'code',
|
|
78
110
|
lang: lang,
|
|
79
|
-
meta:
|
|
111
|
+
meta: title,
|
|
80
112
|
value: (child as unknown as Code).value,
|
|
81
113
|
} as unknown as ElementContent);
|
|
82
|
-
}
|
|
114
|
+
});
|
|
83
115
|
|
|
84
116
|
const newNode: Element = {
|
|
85
117
|
type: 'element',
|
|
@@ -88,13 +120,15 @@ export function gitBookScrapeCodeGroup(
|
|
|
88
120
|
children: tabChildren as Array<ElementContent>,
|
|
89
121
|
};
|
|
90
122
|
|
|
123
|
+
parent.children.length = 0;
|
|
124
|
+
|
|
91
125
|
return newNode;
|
|
92
126
|
}
|
|
93
127
|
|
|
94
128
|
export function readmeScrapeCodeGroup(
|
|
95
129
|
node: HastNode,
|
|
96
130
|
_: HastNodeIndex,
|
|
97
|
-
|
|
131
|
+
__: HastNodeParent
|
|
98
132
|
): Element | undefined {
|
|
99
133
|
if (
|
|
100
134
|
node.tagName !== 'div' ||
|
|
@@ -105,52 +139,53 @@ export function readmeScrapeCodeGroup(
|
|
|
105
139
|
return undefined;
|
|
106
140
|
}
|
|
107
141
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
const titles: Array<string> = [];
|
|
112
|
-
visit(tabTitles, 'element', function (subNode) {
|
|
113
|
-
visit(subNode, 'text', function (textNode) {
|
|
114
|
-
titles.push(textNode.value);
|
|
115
|
-
return EXIT;
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
assertIsDefined(parent);
|
|
120
|
-
node.children.shift();
|
|
121
|
-
|
|
122
|
-
let lang = '';
|
|
123
|
-
visit(node, 'element', function (subNode, _, subParent) {
|
|
142
|
+
let newNode: Element | undefined = undefined;
|
|
143
|
+
visit(node, 'element', function (node) {
|
|
124
144
|
if (
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
'dataLang' in subNode.properties
|
|
145
|
+
node.tagName !== 'div' ||
|
|
146
|
+
!node.properties.className ||
|
|
147
|
+
!Array.isArray(node.properties.className) ||
|
|
148
|
+
!node.properties.className.includes('CodeTabs-inner')
|
|
130
149
|
) {
|
|
131
|
-
|
|
132
|
-
return EXIT;
|
|
150
|
+
return CONTINUE;
|
|
133
151
|
}
|
|
134
|
-
});
|
|
135
152
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
} as unknown as ElementContent);
|
|
146
|
-
}
|
|
153
|
+
const langs: Array<string> = [];
|
|
154
|
+
const titles: Array<string> = [];
|
|
155
|
+
visit(node, 'element', function (subNode) {
|
|
156
|
+
if (
|
|
157
|
+
subNode.tagName !== 'code' ||
|
|
158
|
+
!Array.isArray(subNode.properties.className) ||
|
|
159
|
+
!subNode.properties.className.includes('rdmd-code')
|
|
160
|
+
)
|
|
161
|
+
return CONTINUE;
|
|
147
162
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
children
|
|
153
|
-
|
|
163
|
+
langs.push((subNode.properties.dataLang as string | undefined) ?? '');
|
|
164
|
+
titles.push((subNode.properties.name as string | undefined) ?? '');
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
const children = turnChildrenIntoMdx(node.children) as Array<ElementContent>;
|
|
168
|
+
const tabChildren: Array<ElementContent> = [];
|
|
169
|
+
children.forEach((child, index) => {
|
|
170
|
+
const lang = langs[index] || 'bash';
|
|
171
|
+
const title = titles[index] || lang;
|
|
172
|
+
tabChildren.push({
|
|
173
|
+
type: 'code',
|
|
174
|
+
lang: lang,
|
|
175
|
+
meta: title,
|
|
176
|
+
value: (child as unknown as Code).value,
|
|
177
|
+
} as unknown as ElementContent);
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
newNode = {
|
|
181
|
+
type: 'element',
|
|
182
|
+
tagName: 'CodeGroup',
|
|
183
|
+
properties: {},
|
|
184
|
+
children: tabChildren as Array<ElementContent>,
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
return EXIT;
|
|
188
|
+
});
|
|
154
189
|
|
|
155
190
|
return newNode;
|
|
156
191
|
}
|
|
@@ -165,6 +200,7 @@ export function docusaurusScrapeCodeGroup(
|
|
|
165
200
|
}
|
|
166
201
|
|
|
167
202
|
if (!tabContainsOnlyCode(node)) return undefined;
|
|
203
|
+
assertIsDefined(parent);
|
|
168
204
|
|
|
169
205
|
const titles: Array<string> = [];
|
|
170
206
|
visit(node, 'element', function (subNode) {
|
|
@@ -175,28 +211,34 @@ export function docusaurusScrapeCodeGroup(
|
|
|
175
211
|
});
|
|
176
212
|
});
|
|
177
213
|
|
|
178
|
-
assertIsDefined(parent);
|
|
179
214
|
parent.children.shift();
|
|
180
215
|
|
|
181
|
-
|
|
182
|
-
visit(
|
|
183
|
-
if (
|
|
184
|
-
|
|
185
|
-
|
|
216
|
+
const langs: Array<string> = [];
|
|
217
|
+
visit(parent, 'element', function (subNode) {
|
|
218
|
+
if (
|
|
219
|
+
subNode.tagName === 'div' &&
|
|
220
|
+
Array.isArray(subNode.properties.className) &&
|
|
221
|
+
subNode.properties.className.find((className) => className.toString().includes('language-'))
|
|
222
|
+
) {
|
|
223
|
+
const lang = subNode.properties.className.find((className) =>
|
|
224
|
+
className.toString().includes('language-')
|
|
225
|
+
);
|
|
226
|
+
langs.push(lang?.toString().replace('language-', '') ?? '');
|
|
186
227
|
}
|
|
187
228
|
});
|
|
188
229
|
|
|
189
230
|
const children = turnChildrenIntoMdx(parent.children) as Array<ElementContent>;
|
|
190
231
|
const tabChildren: Array<ElementContent> = [];
|
|
191
|
-
|
|
192
|
-
const
|
|
232
|
+
children.forEach((child, index) => {
|
|
233
|
+
const lang = langs[index] || 'bash';
|
|
234
|
+
const title = titles[index] || lang;
|
|
193
235
|
tabChildren.push({
|
|
194
236
|
type: 'code',
|
|
195
237
|
lang: lang,
|
|
196
|
-
meta:
|
|
238
|
+
meta: title,
|
|
197
239
|
value: (child as unknown as Code).value,
|
|
198
240
|
} as unknown as ElementContent);
|
|
199
|
-
}
|
|
241
|
+
});
|
|
200
242
|
|
|
201
243
|
const newNode: Element = {
|
|
202
244
|
type: 'element',
|
|
@@ -205,5 +247,7 @@ export function docusaurusScrapeCodeGroup(
|
|
|
205
247
|
children: tabChildren as Array<ElementContent>,
|
|
206
248
|
};
|
|
207
249
|
|
|
250
|
+
parent.children.length = 0;
|
|
251
|
+
|
|
208
252
|
return newNode;
|
|
209
253
|
}
|
package/src/components/Tabs.ts
CHANGED
|
@@ -55,47 +55,80 @@ export function gitBookScrapeTabs(
|
|
|
55
55
|
export function readmeScrapeTabs(
|
|
56
56
|
node: HastNode,
|
|
57
57
|
_: HastNodeIndex,
|
|
58
|
-
|
|
58
|
+
__: HastNodeParent
|
|
59
59
|
): Element | undefined {
|
|
60
60
|
if (
|
|
61
61
|
(node.tagName !== 'div' && node.tagName !== 'a') ||
|
|
62
62
|
!node.properties.className ||
|
|
63
63
|
!Array.isArray(node.properties.className) ||
|
|
64
|
-
!node.properties.className.includes('tabbed-component')
|
|
64
|
+
(!node.properties.className.includes('tabbed-component') &&
|
|
65
|
+
!node.properties.className.includes('tabs') &&
|
|
66
|
+
!node.properties.className.includes('Tabs'))
|
|
65
67
|
) {
|
|
66
68
|
return undefined;
|
|
67
69
|
}
|
|
68
70
|
|
|
69
|
-
if (
|
|
70
|
-
const tabTitles = node.children[0];
|
|
71
|
+
if (!node.children[0] || !node.children[1]) return undefined;
|
|
71
72
|
|
|
72
73
|
const titles: Array<string> = [];
|
|
73
|
-
|
|
74
|
-
visit(subNode, 'text', function (textNode) {
|
|
75
|
-
titles.push(textNode.value);
|
|
76
|
-
return EXIT;
|
|
77
|
-
});
|
|
78
|
-
});
|
|
74
|
+
const tabContents: Array<Element> = [];
|
|
79
75
|
|
|
80
|
-
|
|
81
|
-
|
|
76
|
+
if (node.children.length !== 2) {
|
|
77
|
+
visit(node, 'element', function (subNode) {
|
|
78
|
+
if (subNode.tagName !== 'label' && subNode.tagName !== 'button') return CONTINUE;
|
|
82
79
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
80
|
+
let title = '';
|
|
81
|
+
visit(subNode, 'text', function (textNode) {
|
|
82
|
+
title += textNode.value;
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
titles.push(title.trim().replace('\n', ''));
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
tabContents.push(
|
|
89
|
+
...(node.children.filter((subNode) => {
|
|
90
|
+
if (
|
|
91
|
+
subNode.type === 'element' &&
|
|
92
|
+
Array.isArray(subNode.properties.className) &&
|
|
93
|
+
(subNode.properties.className.includes('tab') ||
|
|
94
|
+
subNode.properties.className.includes('Tab') ||
|
|
95
|
+
subNode.properties.className.includes('tabbed-content') ||
|
|
96
|
+
subNode.properties.className.includes('tab-content'))
|
|
97
|
+
)
|
|
98
|
+
return true;
|
|
99
|
+
return false;
|
|
100
|
+
}) as Array<Element>)
|
|
101
|
+
);
|
|
102
|
+
} else {
|
|
103
|
+
const tabTitles = node.children[0];
|
|
104
|
+
|
|
105
|
+
visit(tabTitles, 'element', function (subNode) {
|
|
106
|
+
visit(subNode, 'text', function (textNode) {
|
|
107
|
+
titles.push(textNode.value);
|
|
108
|
+
return EXIT;
|
|
95
109
|
});
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
node.children.shift();
|
|
113
|
+
if (node.children[0].type === 'element') {
|
|
114
|
+
tabContents.push(...(node.children[0].children as Array<Element>));
|
|
96
115
|
}
|
|
97
116
|
}
|
|
98
117
|
|
|
118
|
+
const tabChildren: Array<ElementContent> = [];
|
|
119
|
+
tabContents.forEach((tab, index) => {
|
|
120
|
+
if (!titles[index]) return;
|
|
121
|
+
const children = turnChildrenIntoMdx([tab]) as Array<ElementContent>;
|
|
122
|
+
tabChildren.push({
|
|
123
|
+
type: 'element',
|
|
124
|
+
tagName: 'Tab',
|
|
125
|
+
properties: {
|
|
126
|
+
title: titles[index],
|
|
127
|
+
},
|
|
128
|
+
children,
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
|
|
99
132
|
const newNode: Element = {
|
|
100
133
|
type: 'element',
|
|
101
134
|
tagName: 'Tabs',
|
package/src/constants.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { activeColors } from './utils/log.js';
|
|
2
2
|
|
|
3
3
|
export const SUPPORTED_MEDIA_EXTENSIONS = [
|
|
4
4
|
'png',
|
|
@@ -51,5 +51,5 @@ ${SPACES}We currently support: ReadMe, GitBook, and Docusaurus`;
|
|
|
51
51
|
export const MDAST_FAILURE_MSG = 'failed to convert MDAST to Markdown string';
|
|
52
52
|
|
|
53
53
|
export const FINAL_SUCCESS_MESSAGE = `We've successfully scraped your docs site.
|
|
54
|
-
${SPACES}We've downloaded the ${
|
|
55
|
-
${SPACES}into ${
|
|
54
|
+
${SPACES}We've downloaded the ${activeColors.cyan}\`navigation\`${activeColors.default} array (and if necessary, the ${activeColors.cyan}\`tabs\`${activeColors.default} array)
|
|
55
|
+
${SPACES}into ${activeColors.blue}\`mint.json\`${activeColors.default}.`;
|
package/src/nav/listItems.ts
CHANGED
|
@@ -33,7 +33,7 @@ export function processListItem(
|
|
|
33
33
|
return undefined;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
let isApiReferenceLink = false;
|
|
36
|
+
let isApiReferenceLink = false as boolean;
|
|
37
37
|
visit(link, 'element', function (subNode) {
|
|
38
38
|
if (
|
|
39
39
|
subNode.tagName === 'span' &&
|
|
@@ -44,7 +44,6 @@ export function processListItem(
|
|
|
44
44
|
return EXIT;
|
|
45
45
|
}
|
|
46
46
|
});
|
|
47
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
48
47
|
if (isApiReferenceLink) return undefined;
|
|
49
48
|
|
|
50
49
|
if (linkHref.startsWith('/')) linkHref = linkHref.substring(1);
|