@mintlify/scraping 3.0.187 → 3.0.188
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/assert.d.ts +5 -0
- package/bin/assert.js +13 -0
- package/bin/assert.js.map +1 -0
- package/bin/cli.js +43 -72
- package/bin/cli.js.map +1 -1
- package/bin/components/Accordion.d.ts +5 -0
- package/bin/components/Accordion.js +54 -0
- package/bin/components/Accordion.js.map +1 -0
- package/bin/components/AccordionGroup.d.ts +5 -0
- package/bin/components/AccordionGroup.js +52 -0
- package/bin/components/AccordionGroup.js.map +1 -0
- package/bin/components/Callout.d.ts +5 -0
- package/bin/components/Callout.js +114 -0
- package/bin/components/Callout.js.map +1 -0
- package/bin/components/Card.d.ts +5 -0
- package/bin/components/Card.js +135 -0
- package/bin/components/Card.js.map +1 -0
- package/bin/components/CardGroup.d.ts +5 -0
- package/bin/components/CardGroup.js +52 -0
- package/bin/components/CardGroup.js.map +1 -0
- package/bin/components/CodeGroup.d.ts +5 -0
- package/bin/components/CodeGroup.js +166 -0
- package/bin/components/CodeGroup.js.map +1 -0
- package/bin/components/Frame.d.ts +5 -0
- package/bin/components/Frame.js +51 -0
- package/bin/components/Frame.js.map +1 -0
- package/bin/components/Tabs.d.ts +5 -0
- package/bin/components/Tabs.js +122 -0
- package/bin/components/Tabs.js.map +1 -0
- package/bin/components/link.d.ts +2 -0
- package/bin/components/link.js +16 -0
- package/bin/components/link.js.map +1 -0
- package/bin/constants.d.ts +6 -7
- package/bin/constants.js +31 -12
- package/bin/constants.js.map +1 -1
- package/bin/customComponents/create.d.ts +10 -0
- package/bin/customComponents/create.js +69 -0
- package/bin/customComponents/create.js.map +1 -0
- package/bin/customComponents/plugin.d.ts +2 -0
- package/bin/customComponents/plugin.js +26 -0
- package/bin/customComponents/plugin.js.map +1 -0
- package/bin/customComponents/selective.d.ts +6 -0
- package/bin/customComponents/selective.js +29 -0
- package/bin/customComponents/selective.js.map +1 -0
- package/bin/nav/iterate.d.ts +2 -0
- package/bin/nav/iterate.js +15 -0
- package/bin/nav/iterate.js.map +1 -0
- package/bin/nav/listItems.d.ts +8 -0
- package/bin/nav/listItems.js +62 -0
- package/bin/nav/listItems.js.map +1 -0
- package/bin/nav/retrieve.d.ts +3 -0
- package/bin/nav/retrieve.js +75 -0
- package/bin/nav/retrieve.js.map +1 -0
- package/bin/nav/root.d.ts +2 -0
- package/bin/nav/root.js +40 -0
- package/bin/nav/root.js.map +1 -0
- package/bin/openapi/generateOpenApiPages.js +2 -2
- package/bin/openapi/generateOpenApiPages.js.map +1 -1
- package/bin/root/retrieve.d.ts +2 -0
- package/bin/root/retrieve.js +46 -0
- package/bin/root/retrieve.js.map +1 -0
- package/bin/scrapingPipeline/group.d.ts +5 -0
- package/bin/scrapingPipeline/group.js +46 -0
- package/bin/scrapingPipeline/group.js.map +1 -0
- package/bin/scrapingPipeline/icon.d.ts +2 -0
- package/bin/scrapingPipeline/icon.js +22 -0
- package/bin/scrapingPipeline/icon.js.map +1 -0
- package/bin/scrapingPipeline/images.d.ts +3 -0
- package/bin/scrapingPipeline/images.js +50 -0
- package/bin/scrapingPipeline/images.js.map +1 -0
- package/bin/scrapingPipeline/logo.d.ts +5 -0
- package/bin/scrapingPipeline/logo.js +92 -0
- package/bin/scrapingPipeline/logo.js.map +1 -0
- package/bin/scrapingPipeline/page.d.ts +6 -0
- package/bin/scrapingPipeline/page.js +102 -0
- package/bin/scrapingPipeline/page.js.map +1 -0
- package/bin/scrapingPipeline/root.d.ts +2 -0
- package/bin/scrapingPipeline/root.js +8 -0
- package/bin/scrapingPipeline/root.js.map +1 -0
- package/bin/scrapingPipeline/site.d.ts +7 -0
- package/bin/scrapingPipeline/site.js +129 -0
- package/bin/scrapingPipeline/site.js.map +1 -0
- package/bin/scrapingPipeline/tabs.d.ts +3 -0
- package/bin/scrapingPipeline/tabs.js +67 -0
- package/bin/scrapingPipeline/tabs.js.map +1 -0
- package/bin/tabs/retrieveReadme.d.ts +3 -0
- package/bin/tabs/retrieveReadme.js +78 -0
- package/bin/tabs/retrieveReadme.js.map +1 -0
- package/bin/tsconfig.build.tsbuildinfo +1 -1
- package/bin/types/components.d.ts +2 -0
- package/bin/types/components.js +2 -0
- package/bin/types/components.js.map +1 -0
- package/bin/types/framework.d.ts +8 -0
- package/bin/types/framework.js +3 -0
- package/bin/types/framework.js.map +1 -0
- package/bin/types/hast.d.ts +6 -0
- package/bin/types/hast.js +2 -0
- package/bin/types/hast.js.map +1 -0
- package/bin/types/result.d.ts +7 -0
- package/bin/types/result.js +2 -0
- package/bin/types/result.js.map +1 -0
- package/bin/types/scrapeFunc.d.ts +3 -0
- package/bin/types/scrapeFunc.js +2 -0
- package/bin/types/scrapeFunc.js.map +1 -0
- package/bin/utils/append.d.ts +1 -0
- package/bin/utils/append.js +12 -0
- package/bin/utils/append.js.map +1 -0
- package/bin/utils/children.d.ts +5 -0
- package/bin/utils/children.js +35 -0
- package/bin/utils/children.js.map +1 -0
- package/bin/utils/className.d.ts +3 -0
- package/bin/utils/className.js +13 -0
- package/bin/utils/className.js.map +1 -0
- package/bin/utils/detectFramework.d.ts +4 -0
- package/bin/utils/detectFramework.js +60 -0
- package/bin/utils/detectFramework.js.map +1 -0
- package/bin/utils/emptyParagraphs.d.ts +3 -0
- package/bin/utils/emptyParagraphs.js +19 -0
- package/bin/utils/emptyParagraphs.js.map +1 -0
- package/bin/utils/errors.d.ts +3 -0
- package/bin/utils/errors.js +16 -0
- package/bin/utils/errors.js.map +1 -0
- package/bin/utils/escape.d.ts +2 -0
- package/bin/utils/escape.js +25 -0
- package/bin/utils/escape.js.map +1 -0
- package/bin/utils/extension.d.ts +3 -0
- package/bin/utils/extension.js +18 -0
- package/bin/utils/extension.js.map +1 -0
- package/bin/utils/file.d.ts +4 -0
- package/bin/utils/file.js +43 -0
- package/bin/utils/file.js.map +1 -0
- package/bin/utils/firstChild.d.ts +2 -0
- package/bin/utils/firstChild.js +12 -0
- package/bin/utils/firstChild.js.map +1 -0
- package/bin/utils/images.d.ts +5 -0
- package/bin/utils/images.js +86 -0
- package/bin/utils/images.js.map +1 -0
- package/bin/utils/img.d.ts +2 -0
- package/bin/utils/img.js +15 -0
- package/bin/utils/img.js.map +1 -0
- package/bin/utils/log.d.ts +18 -0
- package/bin/utils/log.js +68 -0
- package/bin/utils/log.js.map +1 -0
- package/bin/utils/nestedRoots.d.ts +7 -0
- package/bin/utils/nestedRoots.js +19 -0
- package/bin/utils/nestedRoots.js.map +1 -0
- package/bin/utils/network.d.ts +5 -0
- package/bin/utils/network.js +82 -0
- package/bin/utils/network.js.map +1 -0
- package/bin/utils/path.d.ts +1 -0
- package/bin/utils/path.js +22 -0
- package/bin/utils/path.js.map +1 -0
- package/bin/utils/position.d.ts +3 -0
- package/bin/utils/position.js +12 -0
- package/bin/utils/position.js.map +1 -0
- package/bin/utils/reservedNames.d.ts +4 -0
- package/bin/utils/reservedNames.js +27 -0
- package/bin/utils/reservedNames.js.map +1 -0
- package/bin/utils/strings.d.ts +2 -0
- package/bin/utils/strings.js +7 -0
- package/bin/utils/strings.js.map +1 -0
- package/bin/utils/text.d.ts +2 -0
- package/bin/utils/text.js +11 -0
- package/bin/utils/text.js.map +1 -0
- package/bin/utils/title.d.ts +10 -0
- package/bin/utils/title.js +58 -0
- package/bin/utils/title.js.map +1 -0
- package/bin/utils/url.d.ts +3 -0
- package/bin/utils/url.js +10 -0
- package/bin/utils/url.js.map +1 -0
- package/package.json +17 -8
- package/src/assert.ts +15 -0
- package/src/cli.ts +53 -90
- package/src/components/Accordion.ts +84 -0
- package/src/components/AccordionGroup.ts +69 -0
- package/src/components/Callout.ts +159 -0
- package/src/components/Card.ts +168 -0
- package/src/components/CardGroup.ts +69 -0
- package/src/components/CodeGroup.ts +209 -0
- package/src/components/Frame.ts +86 -0
- package/src/components/Tabs.ts +154 -0
- package/src/components/link.ts +17 -0
- package/src/constants.ts +37 -19
- package/src/customComponents/create.ts +106 -0
- package/src/customComponents/plugin.ts +31 -0
- package/src/customComponents/selective.ts +37 -0
- package/src/nav/iterate.ts +18 -0
- package/src/nav/listItems.ts +82 -0
- package/src/nav/retrieve.ts +88 -0
- package/src/nav/root.ts +47 -0
- package/src/openapi/generateOpenApiPages.ts +2 -2
- package/src/root/retrieve.ts +52 -0
- package/src/scrapingPipeline/group.ts +62 -0
- package/src/scrapingPipeline/icon.ts +26 -0
- package/src/scrapingPipeline/images.ts +67 -0
- package/src/scrapingPipeline/logo.ts +127 -0
- package/src/scrapingPipeline/page.ts +130 -0
- package/src/scrapingPipeline/root.ts +10 -0
- package/src/scrapingPipeline/site.ts +161 -0
- package/src/scrapingPipeline/tabs.ts +87 -0
- package/src/tabs/retrieveReadme.ts +99 -0
- package/src/types/components.ts +3 -0
- package/src/types/framework.ts +10 -0
- package/src/types/hast.ts +12 -0
- package/src/types/result.ts +1 -0
- package/src/types/scrapeFunc.ts +9 -0
- package/src/utils/append.ts +9 -0
- package/src/utils/children.ts +51 -0
- package/src/utils/className.ts +14 -0
- package/src/utils/detectFramework.ts +72 -0
- package/src/utils/emptyParagraphs.ts +21 -0
- package/src/utils/errors.ts +24 -0
- package/src/utils/escape.ts +30 -0
- package/src/utils/extension.ts +19 -0
- package/src/utils/file.ts +58 -0
- package/src/utils/firstChild.ts +13 -0
- package/src/utils/images.ts +101 -0
- package/src/utils/img.ts +17 -0
- package/src/utils/log.ts +82 -0
- package/src/utils/nestedRoots.ts +20 -0
- package/src/utils/network.ts +95 -0
- package/src/utils/path.ts +27 -0
- package/src/utils/position.ts +14 -0
- package/src/utils/reservedNames.ts +31 -0
- package/src/utils/strings.ts +7 -0
- package/src/utils/text.ts +11 -0
- package/src/utils/title.ts +68 -0
- package/src/utils/url.ts +8 -0
- package/bin/browser.d.ts +0 -2
- package/bin/browser.js +0 -24
- package/bin/browser.js.map +0 -1
- package/bin/checks.d.ts +0 -8
- package/bin/checks.js +0 -24
- package/bin/checks.js.map +0 -1
- package/bin/downloadImage.d.ts +0 -5
- package/bin/downloadImage.js +0 -88
- package/bin/downloadImage.js.map +0 -1
- package/bin/scraping/combineNavWithEmptyGroupTitles.d.ts +0 -2
- package/bin/scraping/combineNavWithEmptyGroupTitles.js +0 -20
- package/bin/scraping/combineNavWithEmptyGroupTitles.js.map +0 -1
- package/bin/scraping/detectFramework.d.ts +0 -9
- package/bin/scraping/detectFramework.js +0 -36
- package/bin/scraping/detectFramework.js.map +0 -1
- package/bin/scraping/downloadAllImages.d.ts +0 -4
- package/bin/scraping/downloadAllImages.js +0 -36
- package/bin/scraping/downloadAllImages.js.map +0 -1
- package/bin/scraping/downloadLogoImage.d.ts +0 -1
- package/bin/scraping/downloadLogoImage.js +0 -12
- package/bin/scraping/downloadLogoImage.js.map +0 -1
- package/bin/scraping/replaceImagePaths.d.ts +0 -1
- package/bin/scraping/replaceImagePaths.js +0 -14
- package/bin/scraping/replaceImagePaths.js.map +0 -1
- package/bin/scraping/scrapeFileGettingFileNameFromUrl.d.ts +0 -6
- package/bin/scraping/scrapeFileGettingFileNameFromUrl.js +0 -46
- package/bin/scraping/scrapeFileGettingFileNameFromUrl.js.map +0 -1
- package/bin/scraping/scrapeGettingFileNameFromUrl.d.ts +0 -6
- package/bin/scraping/scrapeGettingFileNameFromUrl.js +0 -13
- package/bin/scraping/scrapeGettingFileNameFromUrl.js.map +0 -1
- package/bin/scraping/scrapePage.d.ts +0 -8
- package/bin/scraping/scrapePage.js +0 -10
- package/bin/scraping/scrapePage.js.map +0 -1
- package/bin/scraping/scrapePageCommands.d.ts +0 -7
- package/bin/scraping/scrapePageCommands.js +0 -50
- package/bin/scraping/scrapePageCommands.js.map +0 -1
- package/bin/scraping/scrapeSection.d.ts +0 -3
- package/bin/scraping/scrapeSection.js +0 -12
- package/bin/scraping/scrapeSection.js.map +0 -1
- package/bin/scraping/scrapeSectionCommands.d.ts +0 -6
- package/bin/scraping/scrapeSectionCommands.js +0 -63
- package/bin/scraping/scrapeSectionCommands.js.map +0 -1
- package/bin/scraping/site-scrapers/Intercom/scrapeIntercomPage.d.ts +0 -5
- package/bin/scraping/site-scrapers/Intercom/scrapeIntercomPage.js +0 -29
- package/bin/scraping/site-scrapers/Intercom/scrapeIntercomPage.js.map +0 -1
- package/bin/scraping/site-scrapers/Intercom/scrapeIntercomSection.d.ts +0 -2
- package/bin/scraping/site-scrapers/Intercom/scrapeIntercomSection.js +0 -31
- package/bin/scraping/site-scrapers/Intercom/scrapeIntercomSection.js.map +0 -1
- package/bin/scraping/site-scrapers/alternateGroupTitle.d.ts +0 -3
- package/bin/scraping/site-scrapers/alternateGroupTitle.js +0 -9
- package/bin/scraping/site-scrapers/alternateGroupTitle.js.map +0 -1
- package/bin/scraping/site-scrapers/links-per-group/getDocusaurusLinksPerGroup.d.ts +0 -5
- package/bin/scraping/site-scrapers/links-per-group/getDocusaurusLinksPerGroup.js +0 -33
- package/bin/scraping/site-scrapers/links-per-group/getDocusaurusLinksPerGroup.js.map +0 -1
- package/bin/scraping/site-scrapers/links-per-group/getLinksRecursively.d.ts +0 -3
- package/bin/scraping/site-scrapers/links-per-group/getLinksRecursively.js +0 -35
- package/bin/scraping/site-scrapers/links-per-group/getLinksRecursively.js.map +0 -1
- package/bin/scraping/site-scrapers/links-per-group/getLinksRecursivelyGitBook.d.ts +0 -3
- package/bin/scraping/site-scrapers/links-per-group/getLinksRecursivelyGitBook.js +0 -33
- package/bin/scraping/site-scrapers/links-per-group/getLinksRecursivelyGitBook.js.map +0 -1
- package/bin/scraping/site-scrapers/openNestedDocusaurusMenus.d.ts +0 -2
- package/bin/scraping/site-scrapers/openNestedDocusaurusMenus.js +0 -30
- package/bin/scraping/site-scrapers/openNestedDocusaurusMenus.js.map +0 -1
- package/bin/scraping/site-scrapers/openNestedGitbookMenus.d.ts +0 -2
- package/bin/scraping/site-scrapers/openNestedGitbookMenus.js +0 -21
- package/bin/scraping/site-scrapers/openNestedGitbookMenus.js.map +0 -1
- package/bin/scraping/site-scrapers/scrapeDocusaurusPage.d.ts +0 -5
- package/bin/scraping/site-scrapers/scrapeDocusaurusPage.js +0 -53
- package/bin/scraping/site-scrapers/scrapeDocusaurusPage.js.map +0 -1
- package/bin/scraping/site-scrapers/scrapeDocusaurusSection.d.ts +0 -2
- package/bin/scraping/site-scrapers/scrapeDocusaurusSection.js +0 -32
- package/bin/scraping/site-scrapers/scrapeDocusaurusSection.js.map +0 -1
- package/bin/scraping/site-scrapers/scrapeGitBookPage.d.ts +0 -5
- package/bin/scraping/site-scrapers/scrapeGitBookPage.js +0 -56
- package/bin/scraping/site-scrapers/scrapeGitBookPage.js.map +0 -1
- package/bin/scraping/site-scrapers/scrapeGitBookSection.d.ts +0 -2
- package/bin/scraping/site-scrapers/scrapeGitBookSection.js +0 -42
- package/bin/scraping/site-scrapers/scrapeGitBookSection.js.map +0 -1
- package/bin/scraping/site-scrapers/scrapeReadMePage.d.ts +0 -5
- package/bin/scraping/site-scrapers/scrapeReadMePage.js +0 -38
- package/bin/scraping/site-scrapers/scrapeReadMePage.js.map +0 -1
- package/bin/scraping/site-scrapers/scrapeReadMeSection.d.ts +0 -2
- package/bin/scraping/site-scrapers/scrapeReadMeSection.js +0 -39
- package/bin/scraping/site-scrapers/scrapeReadMeSection.js.map +0 -1
- package/bin/util.d.ts +0 -29
- package/bin/util.js +0 -97
- package/bin/util.js.map +0 -1
- package/src/browser.ts +0 -24
- package/src/checks.ts +0 -32
- package/src/downloadImage.ts +0 -102
- package/src/scraping/combineNavWithEmptyGroupTitles.ts +0 -21
- package/src/scraping/detectFramework.ts +0 -55
- package/src/scraping/downloadAllImages.ts +0 -61
- package/src/scraping/downloadLogoImage.ts +0 -24
- package/src/scraping/replaceImagePaths.ts +0 -17
- package/src/scraping/scrapeFileGettingFileNameFromUrl.ts +0 -84
- package/src/scraping/scrapeGettingFileNameFromUrl.ts +0 -56
- package/src/scraping/scrapePage.ts +0 -40
- package/src/scraping/scrapePageCommands.ts +0 -68
- package/src/scraping/scrapeSection.ts +0 -30
- package/src/scraping/scrapeSectionCommands.ts +0 -98
- package/src/scraping/site-scrapers/Intercom/scrapeIntercomPage.ts +0 -52
- package/src/scraping/site-scrapers/Intercom/scrapeIntercomSection.ts +0 -54
- package/src/scraping/site-scrapers/alternateGroupTitle.ts +0 -11
- package/src/scraping/site-scrapers/links-per-group/getDocusaurusLinksPerGroup.ts +0 -45
- package/src/scraping/site-scrapers/links-per-group/getLinksRecursively.ts +0 -47
- package/src/scraping/site-scrapers/links-per-group/getLinksRecursivelyGitBook.ts +0 -44
- package/src/scraping/site-scrapers/openNestedDocusaurusMenus.ts +0 -42
- package/src/scraping/site-scrapers/openNestedGitbookMenus.ts +0 -27
- package/src/scraping/site-scrapers/scrapeDocusaurusPage.ts +0 -85
- package/src/scraping/site-scrapers/scrapeDocusaurusSection.ts +0 -63
- package/src/scraping/site-scrapers/scrapeGitBookPage.ts +0 -82
- package/src/scraping/site-scrapers/scrapeGitBookSection.ts +0 -69
- package/src/scraping/site-scrapers/scrapeReadMePage.ts +0 -56
- package/src/scraping/site-scrapers/scrapeReadMeSection.ts +0 -66
- package/src/util.ts +0 -122
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { Element } from 'hast';
|
|
2
|
+
|
|
3
|
+
import type { HastNode, HastNodeIndex, HastNodeParent } from '../types/hast.js';
|
|
4
|
+
|
|
5
|
+
export function gitBookScrapeCardGroup(
|
|
6
|
+
node: HastNode,
|
|
7
|
+
_: HastNodeIndex,
|
|
8
|
+
parent: HastNodeParent
|
|
9
|
+
): Element | undefined {
|
|
10
|
+
if (node.tagName !== 'Card') return undefined;
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
12
|
+
if (!parent || !parent.children) return undefined;
|
|
13
|
+
|
|
14
|
+
let cardCount = 0;
|
|
15
|
+
for (const child of parent.children) {
|
|
16
|
+
if (child.type === 'element' && child.tagName === 'Card') cardCount++;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (cardCount === parent.children.length) {
|
|
20
|
+
parent.type = 'element';
|
|
21
|
+
(parent as Element).tagName = 'CardGroup';
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function readmeScrapeCardGroup(
|
|
28
|
+
node: HastNode,
|
|
29
|
+
_: HastNodeIndex,
|
|
30
|
+
parent: HastNodeParent
|
|
31
|
+
): Element | undefined {
|
|
32
|
+
if (node.tagName !== 'Card') return undefined;
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
34
|
+
if (!parent || !parent.children) return undefined;
|
|
35
|
+
|
|
36
|
+
let cardCount = 0;
|
|
37
|
+
for (const child of parent.children) {
|
|
38
|
+
if (child.type === 'element' && child.tagName === 'Card') cardCount++;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (cardCount === parent.children.length) {
|
|
42
|
+
parent.type = 'element';
|
|
43
|
+
(parent as Element).tagName = 'CardGroup';
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function docusaurusScrapeCardGroup(
|
|
50
|
+
node: HastNode,
|
|
51
|
+
_: HastNodeIndex,
|
|
52
|
+
parent: HastNodeParent
|
|
53
|
+
): Element | undefined {
|
|
54
|
+
if (node.tagName !== 'Card') return undefined;
|
|
55
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
56
|
+
if (!parent || !parent.children) return undefined;
|
|
57
|
+
|
|
58
|
+
let cardCount = 0;
|
|
59
|
+
for (const child of parent.children) {
|
|
60
|
+
if (child.type === 'element' && child.tagName === 'Card') cardCount++;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (cardCount === parent.children.length) {
|
|
64
|
+
parent.type = 'element';
|
|
65
|
+
(parent as Element).tagName = 'CardGroup';
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import type { Element, ElementContent } from 'hast';
|
|
2
|
+
import type { Code } from 'mdast';
|
|
3
|
+
import { visit, CONTINUE, EXIT } from 'unist-util-visit';
|
|
4
|
+
|
|
5
|
+
import { assertIsDefined } from '../assert.js';
|
|
6
|
+
import type { HastNode, HastNodeIndex, HastNodeParent } from '../types/hast.js';
|
|
7
|
+
import { turnChildrenIntoMdx } from '../utils/children.js';
|
|
8
|
+
|
|
9
|
+
function tabContainsOnlyCode(node: Element): boolean {
|
|
10
|
+
let tabsCount = 0;
|
|
11
|
+
let onlyCodeCount = 0;
|
|
12
|
+
|
|
13
|
+
visit(node, 'element', function (subNode) {
|
|
14
|
+
if (subNode.properties.role && subNode.properties.role === 'tabpanel') tabsCount++;
|
|
15
|
+
visit(subNode, 'element', function (tabNode, index, parent) {
|
|
16
|
+
if (tabNode.tagName === 'button' && typeof index === 'number' && parent) {
|
|
17
|
+
parent.children.splice(index, 1);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
if (
|
|
21
|
+
subNode.children[0] &&
|
|
22
|
+
subNode.children[1] &&
|
|
23
|
+
subNode.children[2] &&
|
|
24
|
+
subNode.children[0].type === 'element' &&
|
|
25
|
+
subNode.children[0].children.length === 1 &&
|
|
26
|
+
subNode.children[1].type === 'element' &&
|
|
27
|
+
subNode.children[1].children.length === 1 &&
|
|
28
|
+
subNode.children[2].type === 'element' &&
|
|
29
|
+
subNode.children[2].children.length > 1 &&
|
|
30
|
+
subNode.children[2].children.length < 4 &&
|
|
31
|
+
subNode.children[2].children.find(
|
|
32
|
+
(child) => child.type === 'element' && (child.tagName === 'pre' || child.tagName === 'code')
|
|
33
|
+
)
|
|
34
|
+
) {
|
|
35
|
+
return onlyCodeCount++;
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
return onlyCodeCount === tabsCount;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function gitBookScrapeCodeGroup(
|
|
42
|
+
node: HastNode,
|
|
43
|
+
_: HastNodeIndex,
|
|
44
|
+
parent: HastNodeParent
|
|
45
|
+
): Element | undefined {
|
|
46
|
+
if (node.tagName !== 'div' || !node.properties.role || node.properties.role !== 'tablist') {
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (!tabContainsOnlyCode(node)) return undefined;
|
|
51
|
+
|
|
52
|
+
const titles: Array<string> = [];
|
|
53
|
+
visit(node, 'element', function (subNode) {
|
|
54
|
+
if (subNode.tagName !== 'button') return CONTINUE;
|
|
55
|
+
visit(subNode, 'text', function (textNode) {
|
|
56
|
+
titles.push(textNode.value);
|
|
57
|
+
return EXIT;
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
assertIsDefined(parent);
|
|
62
|
+
parent.children.shift();
|
|
63
|
+
|
|
64
|
+
let lang = '';
|
|
65
|
+
visit(node, 'element', function (subNode) {
|
|
66
|
+
if (subNode.tagName === 'code' && 'id' in subNode.properties) {
|
|
67
|
+
lang = subNode.properties.id as string;
|
|
68
|
+
return EXIT;
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
const children = turnChildrenIntoMdx(parent.children) as Array<ElementContent>;
|
|
73
|
+
const tabChildren: Array<ElementContent> = [];
|
|
74
|
+
for (let childIndex = 0; childIndex < children.length; childIndex++) {
|
|
75
|
+
const child = children[childIndex];
|
|
76
|
+
tabChildren.push({
|
|
77
|
+
type: 'code',
|
|
78
|
+
lang: lang,
|
|
79
|
+
meta: titles[childIndex],
|
|
80
|
+
value: (child as unknown as Code).value,
|
|
81
|
+
} as unknown as ElementContent);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const newNode: Element = {
|
|
85
|
+
type: 'element',
|
|
86
|
+
tagName: 'CodeGroup',
|
|
87
|
+
properties: {},
|
|
88
|
+
children: tabChildren as Array<ElementContent>,
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
return newNode;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function readmeScrapeCodeGroup(
|
|
95
|
+
node: HastNode,
|
|
96
|
+
_: HastNodeIndex,
|
|
97
|
+
parent: HastNodeParent
|
|
98
|
+
): Element | undefined {
|
|
99
|
+
if (
|
|
100
|
+
node.tagName !== 'div' ||
|
|
101
|
+
!node.properties.className ||
|
|
102
|
+
!Array.isArray(node.properties.className) ||
|
|
103
|
+
!node.properties.className.includes('CodeTabs')
|
|
104
|
+
) {
|
|
105
|
+
return undefined;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (node.children.length !== 2 || !node.children[0] || !node.children[1]) return undefined;
|
|
109
|
+
const tabTitles = node.children[0];
|
|
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) {
|
|
124
|
+
if (
|
|
125
|
+
subNode.tagName === 'code' &&
|
|
126
|
+
subParent &&
|
|
127
|
+
subParent.type === 'element' &&
|
|
128
|
+
subParent.tagName === 'pre' &&
|
|
129
|
+
'dataLang' in subNode.properties
|
|
130
|
+
) {
|
|
131
|
+
lang = subNode.properties.dataLang as string;
|
|
132
|
+
return EXIT;
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
const children = turnChildrenIntoMdx(node.children) as Array<ElementContent>;
|
|
137
|
+
const tabChildren: Array<ElementContent> = [];
|
|
138
|
+
for (let childIndex = 0; childIndex < children.length; childIndex++) {
|
|
139
|
+
const child = children[childIndex];
|
|
140
|
+
tabChildren.push({
|
|
141
|
+
type: 'code',
|
|
142
|
+
lang: lang,
|
|
143
|
+
meta: titles[childIndex],
|
|
144
|
+
value: (child as unknown as Code).value,
|
|
145
|
+
} as unknown as ElementContent);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const newNode: Element = {
|
|
149
|
+
type: 'element',
|
|
150
|
+
tagName: 'CodeGroup',
|
|
151
|
+
properties: {},
|
|
152
|
+
children: tabChildren as Array<ElementContent>,
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
return newNode;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export function docusaurusScrapeCodeGroup(
|
|
159
|
+
node: HastNode,
|
|
160
|
+
_: HastNodeIndex,
|
|
161
|
+
parent: HastNodeParent
|
|
162
|
+
): Element | undefined {
|
|
163
|
+
if (node.tagName !== 'div' || !node.properties.role || node.properties.role !== 'tablist') {
|
|
164
|
+
return undefined;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (!tabContainsOnlyCode(node)) return undefined;
|
|
168
|
+
|
|
169
|
+
const titles: Array<string> = [];
|
|
170
|
+
visit(node, 'element', function (subNode) {
|
|
171
|
+
if (subNode.tagName !== 'li') return CONTINUE;
|
|
172
|
+
visit(subNode, 'text', function (textNode) {
|
|
173
|
+
titles.push(textNode.value);
|
|
174
|
+
return EXIT;
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
assertIsDefined(parent);
|
|
179
|
+
parent.children.shift();
|
|
180
|
+
|
|
181
|
+
let lang = '';
|
|
182
|
+
visit(node, 'element', function (subNode) {
|
|
183
|
+
if (Array.isArray(subNode.properties.className) && subNode.properties.className.length > 0) {
|
|
184
|
+
lang = subNode.properties.className[0] as string;
|
|
185
|
+
lang = lang.replace('language-', '');
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
const children = turnChildrenIntoMdx(parent.children) as Array<ElementContent>;
|
|
190
|
+
const tabChildren: Array<ElementContent> = [];
|
|
191
|
+
for (let childIndex = 0; childIndex < children.length; childIndex++) {
|
|
192
|
+
const child = children[childIndex];
|
|
193
|
+
tabChildren.push({
|
|
194
|
+
type: 'code',
|
|
195
|
+
lang: lang,
|
|
196
|
+
meta: titles[childIndex],
|
|
197
|
+
value: (child as unknown as Code).value,
|
|
198
|
+
} as unknown as ElementContent);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const newNode: Element = {
|
|
202
|
+
type: 'element',
|
|
203
|
+
tagName: 'CodeGroup',
|
|
204
|
+
properties: {},
|
|
205
|
+
children: tabChildren as Array<ElementContent>,
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
return newNode;
|
|
209
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { Element, ElementContent } from 'hast';
|
|
2
|
+
|
|
3
|
+
import type { HastNode, HastNodeIndex, HastNodeParent } from '../types/hast.js';
|
|
4
|
+
import { turnChildrenIntoMdx } from '../utils/children.js';
|
|
5
|
+
import { findTitle } from '../utils/title.js';
|
|
6
|
+
|
|
7
|
+
export function gitBookScrapeFrame(
|
|
8
|
+
node: HastNode,
|
|
9
|
+
_: HastNodeIndex,
|
|
10
|
+
__: HastNodeParent
|
|
11
|
+
): Element | undefined {
|
|
12
|
+
if (
|
|
13
|
+
(node.tagName === 'figure' &&
|
|
14
|
+
node.children.find(
|
|
15
|
+
(subNode) => subNode.type === 'element' && subNode.tagName === 'picture'
|
|
16
|
+
)) ||
|
|
17
|
+
(node.tagName !== 'picture' && node.tagName !== 'figure')
|
|
18
|
+
)
|
|
19
|
+
return undefined;
|
|
20
|
+
|
|
21
|
+
const newNode: Element = {
|
|
22
|
+
type: 'element',
|
|
23
|
+
tagName: 'Frame',
|
|
24
|
+
properties: {},
|
|
25
|
+
children: turnChildrenIntoMdx(node.children, { jsxImages: true }) as Array<ElementContent>,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const caption = findTitle(newNode);
|
|
29
|
+
if (caption) newNode.properties.caption = caption;
|
|
30
|
+
|
|
31
|
+
return newNode;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function readmeScrapeFrame(
|
|
35
|
+
node: HastNode,
|
|
36
|
+
_: HastNodeIndex,
|
|
37
|
+
__: HastNodeParent
|
|
38
|
+
): Element | undefined {
|
|
39
|
+
if (
|
|
40
|
+
(node.tagName === 'figure' &&
|
|
41
|
+
node.children.find(
|
|
42
|
+
(subNode) => subNode.type === 'element' && subNode.tagName === 'picture'
|
|
43
|
+
)) ||
|
|
44
|
+
(node.tagName !== 'picture' && node.tagName !== 'figure')
|
|
45
|
+
)
|
|
46
|
+
return undefined;
|
|
47
|
+
|
|
48
|
+
const newNode: Element = {
|
|
49
|
+
type: 'element',
|
|
50
|
+
tagName: 'Frame',
|
|
51
|
+
properties: {},
|
|
52
|
+
children: turnChildrenIntoMdx(node.children, { jsxImages: true }) as Array<ElementContent>,
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const caption = findTitle(newNode);
|
|
56
|
+
if (caption) newNode.properties.caption = caption;
|
|
57
|
+
|
|
58
|
+
return newNode;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function docusaurusScrapeFrame(
|
|
62
|
+
node: HastNode,
|
|
63
|
+
_: HastNodeIndex,
|
|
64
|
+
__: HastNodeParent
|
|
65
|
+
): Element | undefined {
|
|
66
|
+
if (
|
|
67
|
+
(node.tagName === 'figure' &&
|
|
68
|
+
node.children.find(
|
|
69
|
+
(subNode) => subNode.type === 'element' && subNode.tagName === 'picture'
|
|
70
|
+
)) ||
|
|
71
|
+
(node.tagName !== 'picture' && node.tagName !== 'figure')
|
|
72
|
+
)
|
|
73
|
+
return undefined;
|
|
74
|
+
|
|
75
|
+
const newNode: Element = {
|
|
76
|
+
type: 'element',
|
|
77
|
+
tagName: 'Frame',
|
|
78
|
+
properties: {},
|
|
79
|
+
children: turnChildrenIntoMdx(node.children, { jsxImages: true }) as Array<ElementContent>,
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const caption = findTitle(newNode);
|
|
83
|
+
if (caption) newNode.properties.caption = caption;
|
|
84
|
+
|
|
85
|
+
return newNode;
|
|
86
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import type { Element, ElementContent } from 'hast';
|
|
2
|
+
import { visit, CONTINUE, EXIT } from 'unist-util-visit';
|
|
3
|
+
|
|
4
|
+
import { assertIsDefined } from '../assert.js';
|
|
5
|
+
import type { HastNode, HastNodeIndex, HastNodeParent } from '../types/hast.js';
|
|
6
|
+
import { turnChildrenIntoMdx } from '../utils/children.js';
|
|
7
|
+
|
|
8
|
+
export function gitBookScrapeTabs(
|
|
9
|
+
node: HastNode,
|
|
10
|
+
_: HastNodeIndex,
|
|
11
|
+
parent: HastNodeParent
|
|
12
|
+
): Element | undefined {
|
|
13
|
+
if (node.tagName !== 'div' || !node.properties.role || node.properties.role !== 'tablist') {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const titles: Array<string> = [];
|
|
18
|
+
visit(node, 'element', function (subNode) {
|
|
19
|
+
if (subNode.tagName !== 'button') return CONTINUE;
|
|
20
|
+
visit(subNode, 'text', function (textNode) {
|
|
21
|
+
titles.push(textNode.value);
|
|
22
|
+
return EXIT;
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
assertIsDefined(parent);
|
|
27
|
+
parent.children.shift();
|
|
28
|
+
|
|
29
|
+
const children = turnChildrenIntoMdx(parent.children) as Array<ElementContent>;
|
|
30
|
+
const tabChildren: Array<ElementContent> = [];
|
|
31
|
+
for (let childIndex = 0; childIndex < children.length; childIndex++) {
|
|
32
|
+
const child = children[childIndex];
|
|
33
|
+
if (child) {
|
|
34
|
+
tabChildren.push({
|
|
35
|
+
type: 'element',
|
|
36
|
+
tagName: 'Tab',
|
|
37
|
+
properties: {
|
|
38
|
+
title: titles[childIndex],
|
|
39
|
+
},
|
|
40
|
+
children: [child],
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const newNode: Element = {
|
|
46
|
+
type: 'element',
|
|
47
|
+
tagName: 'Tabs',
|
|
48
|
+
properties: {},
|
|
49
|
+
children: tabChildren as Array<ElementContent>,
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
return newNode;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function readmeScrapeTabs(
|
|
56
|
+
node: HastNode,
|
|
57
|
+
_: HastNodeIndex,
|
|
58
|
+
parent: HastNodeParent
|
|
59
|
+
): Element | undefined {
|
|
60
|
+
if (
|
|
61
|
+
(node.tagName !== 'div' && node.tagName !== 'a') ||
|
|
62
|
+
!node.properties.className ||
|
|
63
|
+
!Array.isArray(node.properties.className) ||
|
|
64
|
+
!node.properties.className.includes('tabbed-component')
|
|
65
|
+
) {
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (node.children.length < 2 || !node.children[0] || !node.children[1]) return undefined;
|
|
70
|
+
const tabTitles = node.children[0];
|
|
71
|
+
|
|
72
|
+
const titles: Array<string> = [];
|
|
73
|
+
visit(tabTitles, 'element', function (subNode) {
|
|
74
|
+
visit(subNode, 'text', function (textNode) {
|
|
75
|
+
titles.push(textNode.value);
|
|
76
|
+
return EXIT;
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
assertIsDefined(parent);
|
|
81
|
+
node.children.shift();
|
|
82
|
+
|
|
83
|
+
const children = turnChildrenIntoMdx(node.children) as Array<ElementContent>;
|
|
84
|
+
const tabChildren: Array<ElementContent> = [];
|
|
85
|
+
for (let childIndex = 0; childIndex < children.length; childIndex++) {
|
|
86
|
+
const child = children[childIndex];
|
|
87
|
+
if (child) {
|
|
88
|
+
tabChildren.push({
|
|
89
|
+
type: 'element',
|
|
90
|
+
tagName: 'Tab',
|
|
91
|
+
properties: {
|
|
92
|
+
title: titles[childIndex],
|
|
93
|
+
},
|
|
94
|
+
children: [child],
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const newNode: Element = {
|
|
100
|
+
type: 'element',
|
|
101
|
+
tagName: 'Tabs',
|
|
102
|
+
properties: {},
|
|
103
|
+
children: tabChildren as Array<ElementContent>,
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
return newNode;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export function docusaurusScrapeTabs(
|
|
110
|
+
node: HastNode,
|
|
111
|
+
_: HastNodeIndex,
|
|
112
|
+
parent: HastNodeParent
|
|
113
|
+
): Element | undefined {
|
|
114
|
+
if (node.tagName !== 'div' || !node.properties.role || node.properties.role !== 'tablist') {
|
|
115
|
+
return undefined;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const titles: Array<string> = [];
|
|
119
|
+
visit(node, 'element', function (subNode) {
|
|
120
|
+
if (subNode.tagName !== 'li') return CONTINUE;
|
|
121
|
+
visit(subNode, 'text', function (textNode) {
|
|
122
|
+
titles.push(textNode.value);
|
|
123
|
+
return EXIT;
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
assertIsDefined(parent);
|
|
128
|
+
parent.children.shift();
|
|
129
|
+
|
|
130
|
+
const children = turnChildrenIntoMdx(parent.children) as Array<ElementContent>;
|
|
131
|
+
const tabChildren: Array<ElementContent> = [];
|
|
132
|
+
for (let childIndex = 0; childIndex < children.length; childIndex++) {
|
|
133
|
+
const child = children[childIndex];
|
|
134
|
+
if (child) {
|
|
135
|
+
tabChildren.push({
|
|
136
|
+
type: 'element',
|
|
137
|
+
tagName: 'Tab',
|
|
138
|
+
properties: {
|
|
139
|
+
title: titles[childIndex],
|
|
140
|
+
},
|
|
141
|
+
children: [child],
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const newNode: Element = {
|
|
147
|
+
type: 'element',
|
|
148
|
+
tagName: 'Tabs',
|
|
149
|
+
properties: {},
|
|
150
|
+
children: tabChildren as Array<ElementContent>,
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
return newNode;
|
|
154
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Root as MdastRoot } from 'mdast';
|
|
2
|
+
import { visit } from 'unist-util-visit';
|
|
3
|
+
|
|
4
|
+
export function convertHeaderLinksToText() {
|
|
5
|
+
return function (tree: MdastRoot) {
|
|
6
|
+
visit(tree, 'heading', function (node) {
|
|
7
|
+
visit(node, 'link', function (subNode, index, parent) {
|
|
8
|
+
if (subNode.url.startsWith('#') && subNode.title == null) {
|
|
9
|
+
if (parent && typeof index === 'number') {
|
|
10
|
+
parent.children.splice(index, 1);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
return tree;
|
|
16
|
+
};
|
|
17
|
+
}
|
package/src/constants.ts
CHANGED
|
@@ -1,22 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import * as url from 'url';
|
|
4
|
-
|
|
5
|
-
// package installation location
|
|
6
|
-
export const INSTALL_PATH = url.fileURLToPath(new URL('.', import.meta.url));
|
|
7
|
-
|
|
8
|
-
export const HOME_DIR = os.homedir();
|
|
9
|
-
|
|
10
|
-
export const DOT_MINTLIFY = path.join(HOME_DIR, '.mintlify');
|
|
11
|
-
|
|
12
|
-
export const VERSION_PATH = path.join(DOT_MINTLIFY, 'mint', 'mint-version.txt');
|
|
13
|
-
|
|
14
|
-
export const CLIENT_PATH = path.join(DOT_MINTLIFY, 'mint', 'client');
|
|
15
|
-
|
|
16
|
-
export const MINT_PATH = path.join(DOT_MINTLIFY, 'mint');
|
|
17
|
-
|
|
18
|
-
// command execution location
|
|
19
|
-
export const CMD_EXEC_PATH = process.cwd();
|
|
1
|
+
import { colors } from './utils/log.js';
|
|
20
2
|
|
|
21
3
|
export const SUPPORTED_MEDIA_EXTENSIONS = [
|
|
22
4
|
'png',
|
|
@@ -35,3 +17,39 @@ export const SUPPORTED_MEDIA_EXTENSIONS = [
|
|
|
35
17
|
'apng',
|
|
36
18
|
'bmp',
|
|
37
19
|
];
|
|
20
|
+
|
|
21
|
+
export const ESCAPED_COMPONENTS = [
|
|
22
|
+
'Accordion',
|
|
23
|
+
'AccordionGroup',
|
|
24
|
+
'Note',
|
|
25
|
+
'Warning',
|
|
26
|
+
'Info',
|
|
27
|
+
'Tip',
|
|
28
|
+
'Check',
|
|
29
|
+
'Card',
|
|
30
|
+
'CardGroup',
|
|
31
|
+
'CodeGroup',
|
|
32
|
+
'Frame',
|
|
33
|
+
'Icon',
|
|
34
|
+
'Steps',
|
|
35
|
+
'Step',
|
|
36
|
+
'Tabs',
|
|
37
|
+
'Tab',
|
|
38
|
+
'Tooltip',
|
|
39
|
+
] as const;
|
|
40
|
+
|
|
41
|
+
export const SPACES = ' '.repeat(13);
|
|
42
|
+
|
|
43
|
+
export const CONTENT_FAILURE_MSG = `failed to retrieve root content from HTML.
|
|
44
|
+
${SPACES}Please double check your documentation provider and ensure they are supported.
|
|
45
|
+
${SPACES}We currently support: ReadMe, GitBook, and Docusaurus`;
|
|
46
|
+
|
|
47
|
+
export const NAV_FAILURE_MSG = `failed to retrieve nav items from HTML.
|
|
48
|
+
${SPACES}Please double check your documentation provider and ensure they are supported.
|
|
49
|
+
${SPACES}We currently support: ReadMe, GitBook, and Docusaurus`;
|
|
50
|
+
|
|
51
|
+
export const MDAST_FAILURE_MSG = 'failed to convert MDAST to Markdown string';
|
|
52
|
+
|
|
53
|
+
export const FINAL_SUCCESS_MESSAGE = `We've successfully scraped your docs site.
|
|
54
|
+
${SPACES}We've downloaded the ${colors.cyan}\`navigation\`${colors.default} array (and if necessary, the ${colors.cyan}\`tabs\`${colors.cyan} array)
|
|
55
|
+
${SPACES}into ${colors.blue}\`mint.json\`${colors.default}.`;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import type { Root as HastRoot, Element } from 'hast';
|
|
2
|
+
import { visit, SKIP, CONTINUE } from 'unist-util-visit';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
gitBookScrapeAccordion,
|
|
6
|
+
readmeScrapeAccordion,
|
|
7
|
+
docusaurusScrapeAccordion,
|
|
8
|
+
} from '../components/Accordion.js';
|
|
9
|
+
import {
|
|
10
|
+
gitBookScrapeAccordionGroup,
|
|
11
|
+
readmeScrapeAccordionGroup,
|
|
12
|
+
docusaurusScrapeAccordionGroup,
|
|
13
|
+
} from '../components/AccordionGroup.js';
|
|
14
|
+
import {
|
|
15
|
+
gitBookScrapeCallout,
|
|
16
|
+
readmeScrapeCallout,
|
|
17
|
+
docusaurusScrapeCallout,
|
|
18
|
+
} from '../components/Callout.js';
|
|
19
|
+
import { gitBookScrapeCard, readmeScrapeCard, docusaurusScrapeCard } from '../components/Card.js';
|
|
20
|
+
import {
|
|
21
|
+
gitBookScrapeCardGroup,
|
|
22
|
+
readmeScrapeCardGroup,
|
|
23
|
+
docusaurusScrapeCardGroup,
|
|
24
|
+
} from '../components/CardGroup.js';
|
|
25
|
+
import {
|
|
26
|
+
gitBookScrapeCodeGroup,
|
|
27
|
+
readmeScrapeCodeGroup,
|
|
28
|
+
docusaurusScrapeCodeGroup,
|
|
29
|
+
} from '../components/CodeGroup.js';
|
|
30
|
+
import {
|
|
31
|
+
gitBookScrapeFrame,
|
|
32
|
+
readmeScrapeFrame,
|
|
33
|
+
docusaurusScrapeFrame,
|
|
34
|
+
} from '../components/Frame.js';
|
|
35
|
+
import { gitBookScrapeTabs, readmeScrapeTabs, docusaurusScrapeTabs } from '../components/Tabs.js';
|
|
36
|
+
import type { ScrapeFuncType } from '../types/scrapeFunc.js';
|
|
37
|
+
import { framework } from '../utils/detectFramework.js';
|
|
38
|
+
import { log } from '../utils/log.js';
|
|
39
|
+
|
|
40
|
+
function createComponent(
|
|
41
|
+
gitBookScrapeFunc: ScrapeFuncType,
|
|
42
|
+
readmeScrapeFunc: ScrapeFuncType,
|
|
43
|
+
docusaurusScrapeFunc: ScrapeFuncType
|
|
44
|
+
) {
|
|
45
|
+
return function (tree: HastRoot) {
|
|
46
|
+
return visit(tree, 'element', function (node, index, parent) {
|
|
47
|
+
if (node.tagName === 'code' || node.tagName === 'pre') return SKIP;
|
|
48
|
+
let result: Element | undefined = undefined;
|
|
49
|
+
|
|
50
|
+
switch (framework.vendor) {
|
|
51
|
+
case 'gitbook':
|
|
52
|
+
result = gitBookScrapeFunc(node, index, parent);
|
|
53
|
+
break;
|
|
54
|
+
case 'readme':
|
|
55
|
+
result = readmeScrapeFunc(node, index, parent);
|
|
56
|
+
break;
|
|
57
|
+
case 'docusaurus':
|
|
58
|
+
result = docusaurusScrapeFunc(node, index, parent);
|
|
59
|
+
break;
|
|
60
|
+
default:
|
|
61
|
+
log('Invalid documentation vendor requested: ' + framework.vendor);
|
|
62
|
+
return SKIP;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (!result) return CONTINUE;
|
|
66
|
+
|
|
67
|
+
if (parent && typeof index === 'number') {
|
|
68
|
+
parent.children[index] = result;
|
|
69
|
+
return SKIP;
|
|
70
|
+
}
|
|
71
|
+
return CONTINUE;
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function createLinks() {
|
|
77
|
+
return createComponent(gitBookScrapeCard, readmeScrapeCard, docusaurusScrapeCard);
|
|
78
|
+
}
|
|
79
|
+
export function createCard() {
|
|
80
|
+
return createComponent(gitBookScrapeCard, readmeScrapeCard, docusaurusScrapeCard);
|
|
81
|
+
}
|
|
82
|
+
export function createAccordion() {
|
|
83
|
+
return createComponent(gitBookScrapeAccordion, readmeScrapeAccordion, docusaurusScrapeAccordion);
|
|
84
|
+
}
|
|
85
|
+
export function createAccordionGroup() {
|
|
86
|
+
return createComponent(
|
|
87
|
+
gitBookScrapeAccordionGroup,
|
|
88
|
+
readmeScrapeAccordionGroup,
|
|
89
|
+
docusaurusScrapeAccordionGroup
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
export function createFrame() {
|
|
93
|
+
return createComponent(gitBookScrapeFrame, readmeScrapeFrame, docusaurusScrapeFrame);
|
|
94
|
+
}
|
|
95
|
+
export function createCodeGroup() {
|
|
96
|
+
return createComponent(gitBookScrapeCodeGroup, readmeScrapeCodeGroup, docusaurusScrapeCodeGroup);
|
|
97
|
+
}
|
|
98
|
+
export function createTabs() {
|
|
99
|
+
return createComponent(gitBookScrapeTabs, readmeScrapeTabs, docusaurusScrapeTabs);
|
|
100
|
+
}
|
|
101
|
+
export function createCallout() {
|
|
102
|
+
return createComponent(gitBookScrapeCallout, readmeScrapeCallout, docusaurusScrapeCallout);
|
|
103
|
+
}
|
|
104
|
+
export function createCardGroup() {
|
|
105
|
+
return createComponent(gitBookScrapeCardGroup, readmeScrapeCardGroup, docusaurusScrapeCardGroup);
|
|
106
|
+
}
|