@mintlify/scraping 3.0.186 → 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.
Files changed (344) hide show
  1. package/bin/assert.d.ts +5 -0
  2. package/bin/assert.js +13 -0
  3. package/bin/assert.js.map +1 -0
  4. package/bin/cli.js +43 -72
  5. package/bin/cli.js.map +1 -1
  6. package/bin/components/Accordion.d.ts +5 -0
  7. package/bin/components/Accordion.js +54 -0
  8. package/bin/components/Accordion.js.map +1 -0
  9. package/bin/components/AccordionGroup.d.ts +5 -0
  10. package/bin/components/AccordionGroup.js +52 -0
  11. package/bin/components/AccordionGroup.js.map +1 -0
  12. package/bin/components/Callout.d.ts +5 -0
  13. package/bin/components/Callout.js +114 -0
  14. package/bin/components/Callout.js.map +1 -0
  15. package/bin/components/Card.d.ts +5 -0
  16. package/bin/components/Card.js +135 -0
  17. package/bin/components/Card.js.map +1 -0
  18. package/bin/components/CardGroup.d.ts +5 -0
  19. package/bin/components/CardGroup.js +52 -0
  20. package/bin/components/CardGroup.js.map +1 -0
  21. package/bin/components/CodeGroup.d.ts +5 -0
  22. package/bin/components/CodeGroup.js +166 -0
  23. package/bin/components/CodeGroup.js.map +1 -0
  24. package/bin/components/Frame.d.ts +5 -0
  25. package/bin/components/Frame.js +51 -0
  26. package/bin/components/Frame.js.map +1 -0
  27. package/bin/components/Tabs.d.ts +5 -0
  28. package/bin/components/Tabs.js +122 -0
  29. package/bin/components/Tabs.js.map +1 -0
  30. package/bin/components/link.d.ts +2 -0
  31. package/bin/components/link.js +16 -0
  32. package/bin/components/link.js.map +1 -0
  33. package/bin/constants.d.ts +6 -7
  34. package/bin/constants.js +31 -12
  35. package/bin/constants.js.map +1 -1
  36. package/bin/customComponents/create.d.ts +10 -0
  37. package/bin/customComponents/create.js +69 -0
  38. package/bin/customComponents/create.js.map +1 -0
  39. package/bin/customComponents/plugin.d.ts +2 -0
  40. package/bin/customComponents/plugin.js +26 -0
  41. package/bin/customComponents/plugin.js.map +1 -0
  42. package/bin/customComponents/selective.d.ts +6 -0
  43. package/bin/customComponents/selective.js +29 -0
  44. package/bin/customComponents/selective.js.map +1 -0
  45. package/bin/nav/iterate.d.ts +2 -0
  46. package/bin/nav/iterate.js +15 -0
  47. package/bin/nav/iterate.js.map +1 -0
  48. package/bin/nav/listItems.d.ts +8 -0
  49. package/bin/nav/listItems.js +62 -0
  50. package/bin/nav/listItems.js.map +1 -0
  51. package/bin/nav/retrieve.d.ts +3 -0
  52. package/bin/nav/retrieve.js +75 -0
  53. package/bin/nav/retrieve.js.map +1 -0
  54. package/bin/nav/root.d.ts +2 -0
  55. package/bin/nav/root.js +40 -0
  56. package/bin/nav/root.js.map +1 -0
  57. package/bin/openapi/generateOpenApiPages.js +18 -5
  58. package/bin/openapi/generateOpenApiPages.js.map +1 -1
  59. package/bin/root/retrieve.d.ts +2 -0
  60. package/bin/root/retrieve.js +46 -0
  61. package/bin/root/retrieve.js.map +1 -0
  62. package/bin/scrapingPipeline/group.d.ts +5 -0
  63. package/bin/scrapingPipeline/group.js +46 -0
  64. package/bin/scrapingPipeline/group.js.map +1 -0
  65. package/bin/scrapingPipeline/icon.d.ts +2 -0
  66. package/bin/scrapingPipeline/icon.js +22 -0
  67. package/bin/scrapingPipeline/icon.js.map +1 -0
  68. package/bin/scrapingPipeline/images.d.ts +3 -0
  69. package/bin/scrapingPipeline/images.js +50 -0
  70. package/bin/scrapingPipeline/images.js.map +1 -0
  71. package/bin/scrapingPipeline/logo.d.ts +5 -0
  72. package/bin/scrapingPipeline/logo.js +92 -0
  73. package/bin/scrapingPipeline/logo.js.map +1 -0
  74. package/bin/scrapingPipeline/page.d.ts +6 -0
  75. package/bin/scrapingPipeline/page.js +102 -0
  76. package/bin/scrapingPipeline/page.js.map +1 -0
  77. package/bin/scrapingPipeline/root.d.ts +2 -0
  78. package/bin/scrapingPipeline/root.js +8 -0
  79. package/bin/scrapingPipeline/root.js.map +1 -0
  80. package/bin/scrapingPipeline/site.d.ts +7 -0
  81. package/bin/scrapingPipeline/site.js +129 -0
  82. package/bin/scrapingPipeline/site.js.map +1 -0
  83. package/bin/scrapingPipeline/tabs.d.ts +3 -0
  84. package/bin/scrapingPipeline/tabs.js +67 -0
  85. package/bin/scrapingPipeline/tabs.js.map +1 -0
  86. package/bin/tabs/retrieveReadme.d.ts +3 -0
  87. package/bin/tabs/retrieveReadme.js +78 -0
  88. package/bin/tabs/retrieveReadme.js.map +1 -0
  89. package/bin/tsconfig.build.tsbuildinfo +1 -1
  90. package/bin/types/components.d.ts +2 -0
  91. package/bin/types/components.js +2 -0
  92. package/bin/types/components.js.map +1 -0
  93. package/bin/types/framework.d.ts +8 -0
  94. package/bin/types/framework.js +3 -0
  95. package/bin/types/framework.js.map +1 -0
  96. package/bin/types/hast.d.ts +6 -0
  97. package/bin/types/hast.js +2 -0
  98. package/bin/types/hast.js.map +1 -0
  99. package/bin/types/result.d.ts +7 -0
  100. package/bin/types/result.js +2 -0
  101. package/bin/types/result.js.map +1 -0
  102. package/bin/types/scrapeFunc.d.ts +3 -0
  103. package/bin/types/scrapeFunc.js +2 -0
  104. package/bin/types/scrapeFunc.js.map +1 -0
  105. package/bin/utils/append.d.ts +1 -0
  106. package/bin/utils/append.js +12 -0
  107. package/bin/utils/append.js.map +1 -0
  108. package/bin/utils/children.d.ts +5 -0
  109. package/bin/utils/children.js +35 -0
  110. package/bin/utils/children.js.map +1 -0
  111. package/bin/utils/className.d.ts +3 -0
  112. package/bin/utils/className.js +13 -0
  113. package/bin/utils/className.js.map +1 -0
  114. package/bin/utils/detectFramework.d.ts +4 -0
  115. package/bin/utils/detectFramework.js +60 -0
  116. package/bin/utils/detectFramework.js.map +1 -0
  117. package/bin/utils/emptyParagraphs.d.ts +3 -0
  118. package/bin/utils/emptyParagraphs.js +19 -0
  119. package/bin/utils/emptyParagraphs.js.map +1 -0
  120. package/bin/utils/errors.d.ts +3 -0
  121. package/bin/utils/errors.js +16 -0
  122. package/bin/utils/errors.js.map +1 -0
  123. package/bin/utils/escape.d.ts +2 -0
  124. package/bin/utils/escape.js +25 -0
  125. package/bin/utils/escape.js.map +1 -0
  126. package/bin/utils/extension.d.ts +3 -0
  127. package/bin/utils/extension.js +18 -0
  128. package/bin/utils/extension.js.map +1 -0
  129. package/bin/utils/file.d.ts +4 -0
  130. package/bin/utils/file.js +43 -0
  131. package/bin/utils/file.js.map +1 -0
  132. package/bin/utils/firstChild.d.ts +2 -0
  133. package/bin/utils/firstChild.js +12 -0
  134. package/bin/utils/firstChild.js.map +1 -0
  135. package/bin/utils/images.d.ts +5 -0
  136. package/bin/utils/images.js +86 -0
  137. package/bin/utils/images.js.map +1 -0
  138. package/bin/utils/img.d.ts +2 -0
  139. package/bin/utils/img.js +15 -0
  140. package/bin/utils/img.js.map +1 -0
  141. package/bin/utils/log.d.ts +18 -0
  142. package/bin/utils/log.js +68 -0
  143. package/bin/utils/log.js.map +1 -0
  144. package/bin/utils/nestedRoots.d.ts +7 -0
  145. package/bin/utils/nestedRoots.js +19 -0
  146. package/bin/utils/nestedRoots.js.map +1 -0
  147. package/bin/utils/network.d.ts +5 -0
  148. package/bin/utils/network.js +82 -0
  149. package/bin/utils/network.js.map +1 -0
  150. package/bin/utils/path.d.ts +1 -0
  151. package/bin/utils/path.js +22 -0
  152. package/bin/utils/path.js.map +1 -0
  153. package/bin/utils/position.d.ts +3 -0
  154. package/bin/utils/position.js +12 -0
  155. package/bin/utils/position.js.map +1 -0
  156. package/bin/utils/reservedNames.d.ts +4 -0
  157. package/bin/utils/reservedNames.js +27 -0
  158. package/bin/utils/reservedNames.js.map +1 -0
  159. package/bin/utils/strings.d.ts +2 -0
  160. package/bin/utils/strings.js +7 -0
  161. package/bin/utils/strings.js.map +1 -0
  162. package/bin/utils/text.d.ts +2 -0
  163. package/bin/utils/text.js +11 -0
  164. package/bin/utils/text.js.map +1 -0
  165. package/bin/utils/title.d.ts +10 -0
  166. package/bin/utils/title.js +58 -0
  167. package/bin/utils/title.js.map +1 -0
  168. package/bin/utils/url.d.ts +3 -0
  169. package/bin/utils/url.js +10 -0
  170. package/bin/utils/url.js.map +1 -0
  171. package/package.json +18 -9
  172. package/src/assert.ts +15 -0
  173. package/src/cli.ts +53 -90
  174. package/src/components/Accordion.ts +84 -0
  175. package/src/components/AccordionGroup.ts +69 -0
  176. package/src/components/Callout.ts +159 -0
  177. package/src/components/Card.ts +168 -0
  178. package/src/components/CardGroup.ts +69 -0
  179. package/src/components/CodeGroup.ts +209 -0
  180. package/src/components/Frame.ts +86 -0
  181. package/src/components/Tabs.ts +154 -0
  182. package/src/components/link.ts +17 -0
  183. package/src/constants.ts +37 -19
  184. package/src/customComponents/create.ts +106 -0
  185. package/src/customComponents/plugin.ts +31 -0
  186. package/src/customComponents/selective.ts +37 -0
  187. package/src/nav/iterate.ts +18 -0
  188. package/src/nav/listItems.ts +82 -0
  189. package/src/nav/retrieve.ts +88 -0
  190. package/src/nav/root.ts +47 -0
  191. package/src/openapi/generateOpenApiPages.ts +19 -4
  192. package/src/root/retrieve.ts +52 -0
  193. package/src/scrapingPipeline/group.ts +62 -0
  194. package/src/scrapingPipeline/icon.ts +26 -0
  195. package/src/scrapingPipeline/images.ts +67 -0
  196. package/src/scrapingPipeline/logo.ts +127 -0
  197. package/src/scrapingPipeline/page.ts +130 -0
  198. package/src/scrapingPipeline/root.ts +10 -0
  199. package/src/scrapingPipeline/site.ts +161 -0
  200. package/src/scrapingPipeline/tabs.ts +87 -0
  201. package/src/tabs/retrieveReadme.ts +99 -0
  202. package/src/types/components.ts +3 -0
  203. package/src/types/framework.ts +10 -0
  204. package/src/types/hast.ts +12 -0
  205. package/src/types/result.ts +1 -0
  206. package/src/types/scrapeFunc.ts +9 -0
  207. package/src/utils/append.ts +9 -0
  208. package/src/utils/children.ts +51 -0
  209. package/src/utils/className.ts +14 -0
  210. package/src/utils/detectFramework.ts +72 -0
  211. package/src/utils/emptyParagraphs.ts +21 -0
  212. package/src/utils/errors.ts +24 -0
  213. package/src/utils/escape.ts +30 -0
  214. package/src/utils/extension.ts +19 -0
  215. package/src/utils/file.ts +58 -0
  216. package/src/utils/firstChild.ts +13 -0
  217. package/src/utils/images.ts +101 -0
  218. package/src/utils/img.ts +17 -0
  219. package/src/utils/log.ts +82 -0
  220. package/src/utils/nestedRoots.ts +20 -0
  221. package/src/utils/network.ts +95 -0
  222. package/src/utils/path.ts +27 -0
  223. package/src/utils/position.ts +14 -0
  224. package/src/utils/reservedNames.ts +31 -0
  225. package/src/utils/strings.ts +7 -0
  226. package/src/utils/text.ts +11 -0
  227. package/src/utils/title.ts +68 -0
  228. package/src/utils/url.ts +8 -0
  229. package/bin/browser.d.ts +0 -2
  230. package/bin/browser.js +0 -24
  231. package/bin/browser.js.map +0 -1
  232. package/bin/checks.d.ts +0 -8
  233. package/bin/checks.js +0 -24
  234. package/bin/checks.js.map +0 -1
  235. package/bin/downloadImage.d.ts +0 -5
  236. package/bin/downloadImage.js +0 -88
  237. package/bin/downloadImage.js.map +0 -1
  238. package/bin/scraping/combineNavWithEmptyGroupTitles.d.ts +0 -2
  239. package/bin/scraping/combineNavWithEmptyGroupTitles.js +0 -20
  240. package/bin/scraping/combineNavWithEmptyGroupTitles.js.map +0 -1
  241. package/bin/scraping/detectFramework.d.ts +0 -9
  242. package/bin/scraping/detectFramework.js +0 -36
  243. package/bin/scraping/detectFramework.js.map +0 -1
  244. package/bin/scraping/downloadAllImages.d.ts +0 -4
  245. package/bin/scraping/downloadAllImages.js +0 -36
  246. package/bin/scraping/downloadAllImages.js.map +0 -1
  247. package/bin/scraping/downloadLogoImage.d.ts +0 -1
  248. package/bin/scraping/downloadLogoImage.js +0 -12
  249. package/bin/scraping/downloadLogoImage.js.map +0 -1
  250. package/bin/scraping/replaceImagePaths.d.ts +0 -1
  251. package/bin/scraping/replaceImagePaths.js +0 -14
  252. package/bin/scraping/replaceImagePaths.js.map +0 -1
  253. package/bin/scraping/scrapeFileGettingFileNameFromUrl.d.ts +0 -6
  254. package/bin/scraping/scrapeFileGettingFileNameFromUrl.js +0 -46
  255. package/bin/scraping/scrapeFileGettingFileNameFromUrl.js.map +0 -1
  256. package/bin/scraping/scrapeGettingFileNameFromUrl.d.ts +0 -6
  257. package/bin/scraping/scrapeGettingFileNameFromUrl.js +0 -13
  258. package/bin/scraping/scrapeGettingFileNameFromUrl.js.map +0 -1
  259. package/bin/scraping/scrapePage.d.ts +0 -8
  260. package/bin/scraping/scrapePage.js +0 -10
  261. package/bin/scraping/scrapePage.js.map +0 -1
  262. package/bin/scraping/scrapePageCommands.d.ts +0 -7
  263. package/bin/scraping/scrapePageCommands.js +0 -50
  264. package/bin/scraping/scrapePageCommands.js.map +0 -1
  265. package/bin/scraping/scrapeSection.d.ts +0 -3
  266. package/bin/scraping/scrapeSection.js +0 -12
  267. package/bin/scraping/scrapeSection.js.map +0 -1
  268. package/bin/scraping/scrapeSectionCommands.d.ts +0 -6
  269. package/bin/scraping/scrapeSectionCommands.js +0 -63
  270. package/bin/scraping/scrapeSectionCommands.js.map +0 -1
  271. package/bin/scraping/site-scrapers/Intercom/scrapeIntercomPage.d.ts +0 -5
  272. package/bin/scraping/site-scrapers/Intercom/scrapeIntercomPage.js +0 -29
  273. package/bin/scraping/site-scrapers/Intercom/scrapeIntercomPage.js.map +0 -1
  274. package/bin/scraping/site-scrapers/Intercom/scrapeIntercomSection.d.ts +0 -2
  275. package/bin/scraping/site-scrapers/Intercom/scrapeIntercomSection.js +0 -31
  276. package/bin/scraping/site-scrapers/Intercom/scrapeIntercomSection.js.map +0 -1
  277. package/bin/scraping/site-scrapers/alternateGroupTitle.d.ts +0 -3
  278. package/bin/scraping/site-scrapers/alternateGroupTitle.js +0 -9
  279. package/bin/scraping/site-scrapers/alternateGroupTitle.js.map +0 -1
  280. package/bin/scraping/site-scrapers/links-per-group/getDocusaurusLinksPerGroup.d.ts +0 -5
  281. package/bin/scraping/site-scrapers/links-per-group/getDocusaurusLinksPerGroup.js +0 -33
  282. package/bin/scraping/site-scrapers/links-per-group/getDocusaurusLinksPerGroup.js.map +0 -1
  283. package/bin/scraping/site-scrapers/links-per-group/getLinksRecursively.d.ts +0 -3
  284. package/bin/scraping/site-scrapers/links-per-group/getLinksRecursively.js +0 -35
  285. package/bin/scraping/site-scrapers/links-per-group/getLinksRecursively.js.map +0 -1
  286. package/bin/scraping/site-scrapers/links-per-group/getLinksRecursivelyGitBook.d.ts +0 -3
  287. package/bin/scraping/site-scrapers/links-per-group/getLinksRecursivelyGitBook.js +0 -33
  288. package/bin/scraping/site-scrapers/links-per-group/getLinksRecursivelyGitBook.js.map +0 -1
  289. package/bin/scraping/site-scrapers/openNestedDocusaurusMenus.d.ts +0 -2
  290. package/bin/scraping/site-scrapers/openNestedDocusaurusMenus.js +0 -30
  291. package/bin/scraping/site-scrapers/openNestedDocusaurusMenus.js.map +0 -1
  292. package/bin/scraping/site-scrapers/openNestedGitbookMenus.d.ts +0 -2
  293. package/bin/scraping/site-scrapers/openNestedGitbookMenus.js +0 -21
  294. package/bin/scraping/site-scrapers/openNestedGitbookMenus.js.map +0 -1
  295. package/bin/scraping/site-scrapers/scrapeDocusaurusPage.d.ts +0 -5
  296. package/bin/scraping/site-scrapers/scrapeDocusaurusPage.js +0 -53
  297. package/bin/scraping/site-scrapers/scrapeDocusaurusPage.js.map +0 -1
  298. package/bin/scraping/site-scrapers/scrapeDocusaurusSection.d.ts +0 -2
  299. package/bin/scraping/site-scrapers/scrapeDocusaurusSection.js +0 -32
  300. package/bin/scraping/site-scrapers/scrapeDocusaurusSection.js.map +0 -1
  301. package/bin/scraping/site-scrapers/scrapeGitBookPage.d.ts +0 -5
  302. package/bin/scraping/site-scrapers/scrapeGitBookPage.js +0 -56
  303. package/bin/scraping/site-scrapers/scrapeGitBookPage.js.map +0 -1
  304. package/bin/scraping/site-scrapers/scrapeGitBookSection.d.ts +0 -2
  305. package/bin/scraping/site-scrapers/scrapeGitBookSection.js +0 -42
  306. package/bin/scraping/site-scrapers/scrapeGitBookSection.js.map +0 -1
  307. package/bin/scraping/site-scrapers/scrapeReadMePage.d.ts +0 -5
  308. package/bin/scraping/site-scrapers/scrapeReadMePage.js +0 -38
  309. package/bin/scraping/site-scrapers/scrapeReadMePage.js.map +0 -1
  310. package/bin/scraping/site-scrapers/scrapeReadMeSection.d.ts +0 -2
  311. package/bin/scraping/site-scrapers/scrapeReadMeSection.js +0 -39
  312. package/bin/scraping/site-scrapers/scrapeReadMeSection.js.map +0 -1
  313. package/bin/util.d.ts +0 -29
  314. package/bin/util.js +0 -97
  315. package/bin/util.js.map +0 -1
  316. package/src/browser.ts +0 -24
  317. package/src/checks.ts +0 -32
  318. package/src/downloadImage.ts +0 -102
  319. package/src/scraping/combineNavWithEmptyGroupTitles.ts +0 -21
  320. package/src/scraping/detectFramework.ts +0 -55
  321. package/src/scraping/downloadAllImages.ts +0 -61
  322. package/src/scraping/downloadLogoImage.ts +0 -24
  323. package/src/scraping/replaceImagePaths.ts +0 -17
  324. package/src/scraping/scrapeFileGettingFileNameFromUrl.ts +0 -84
  325. package/src/scraping/scrapeGettingFileNameFromUrl.ts +0 -56
  326. package/src/scraping/scrapePage.ts +0 -40
  327. package/src/scraping/scrapePageCommands.ts +0 -68
  328. package/src/scraping/scrapeSection.ts +0 -30
  329. package/src/scraping/scrapeSectionCommands.ts +0 -98
  330. package/src/scraping/site-scrapers/Intercom/scrapeIntercomPage.ts +0 -52
  331. package/src/scraping/site-scrapers/Intercom/scrapeIntercomSection.ts +0 -54
  332. package/src/scraping/site-scrapers/alternateGroupTitle.ts +0 -11
  333. package/src/scraping/site-scrapers/links-per-group/getDocusaurusLinksPerGroup.ts +0 -45
  334. package/src/scraping/site-scrapers/links-per-group/getLinksRecursively.ts +0 -47
  335. package/src/scraping/site-scrapers/links-per-group/getLinksRecursivelyGitBook.ts +0 -44
  336. package/src/scraping/site-scrapers/openNestedDocusaurusMenus.ts +0 -42
  337. package/src/scraping/site-scrapers/openNestedGitbookMenus.ts +0 -27
  338. package/src/scraping/site-scrapers/scrapeDocusaurusPage.ts +0 -85
  339. package/src/scraping/site-scrapers/scrapeDocusaurusSection.ts +0 -63
  340. package/src/scraping/site-scrapers/scrapeGitBookPage.ts +0 -82
  341. package/src/scraping/site-scrapers/scrapeGitBookSection.ts +0 -69
  342. package/src/scraping/site-scrapers/scrapeReadMePage.ts +0 -56
  343. package/src/scraping/site-scrapers/scrapeReadMeSection.ts +0 -66
  344. package/src/util.ts +0 -122
@@ -0,0 +1,31 @@
1
+ import type { Root as HastRoot, Element } from 'hast';
2
+ import type { BlockContent, DefinitionContent } from 'mdast';
3
+ import type { MdxJsxFlowElement } from 'mdast-util-mdx-jsx';
4
+ import { visit } from 'unist-util-visit';
5
+
6
+ import { ESCAPED_COMPONENTS } from '../constants.js';
7
+ import type { EscapedComponent } from '../types/components.js';
8
+
9
+ export function rehypeToRemarkCustomComponents() {
10
+ return function (tree: HastRoot) {
11
+ visit(tree, 'element', function (node: Element, index, parent) {
12
+ if (ESCAPED_COMPONENTS.includes(node.tagName as unknown as EscapedComponent)) {
13
+ const newNode: MdxJsxFlowElement = {
14
+ type: 'mdxJsxFlowElement',
15
+ name: node.tagName,
16
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
17
+ attributes: Object.entries(node.properties || {}).map(([key, value]) => ({
18
+ type: 'mdxJsxAttribute',
19
+ name: key,
20
+ value: value as string,
21
+ })),
22
+ children: node.children as Array<BlockContent | DefinitionContent>,
23
+ };
24
+ if (parent && typeof index === 'number') {
25
+ parent.children[index] = newNode as unknown as Element;
26
+ }
27
+ }
28
+ });
29
+ return tree;
30
+ };
31
+ }
@@ -0,0 +1,37 @@
1
+ import type { Root as HastRoot, Element } from 'hast';
2
+ import { toMdast, defaultHandlers } from 'hast-util-to-mdast';
3
+ import type { State, Handle } from 'hast-util-to-mdast';
4
+ import type { Root as MdastRoot } from 'mdast';
5
+ import type { BlockContent, DefinitionContent } from 'mdast';
6
+ import type { MdxJsxFlowElement } from 'mdast-util-mdx-jsx';
7
+
8
+ import { ESCAPED_COMPONENTS } from '../constants.js';
9
+
10
+ export function mdxJsxFlowElementHandler(_: State, node: Element): MdxJsxFlowElement {
11
+ return {
12
+ type: 'mdxJsxFlowElement',
13
+ name: node.tagName,
14
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
15
+ attributes: Object.entries(node.properties ?? {}).map(([key, value]) => ({
16
+ type: 'mdxJsxAttribute',
17
+ name: key,
18
+ value: value as string,
19
+ })),
20
+ children: node.children as Array<BlockContent | DefinitionContent>,
21
+ };
22
+ }
23
+
24
+ export function selectiveRehypeRemark() {
25
+ const handlers: Record<string, Handle> = { ...defaultHandlers };
26
+ ESCAPED_COMPONENTS.forEach((tagName) => {
27
+ handlers[tagName] = mdxJsxFlowElementHandler;
28
+ });
29
+ handlers.mdxJsxFlowElement = mdxJsxFlowElementHandler;
30
+
31
+ return function (tree: HastRoot) {
32
+ const newTree = toMdast(tree, {
33
+ handlers,
34
+ }) as MdastRoot;
35
+ return newTree;
36
+ };
37
+ }
@@ -0,0 +1,18 @@
1
+ import { NavigationEntry } from '@mintlify/models';
2
+
3
+ export function iterateOverNavItems(navItems: Array<NavigationEntry>, origin: string): Array<URL> {
4
+ return navItems.flatMap((navItem) => recurseOverGroup(navItem, origin));
5
+ }
6
+
7
+ function recurseOverGroup(group: NavigationEntry, origin: string): Array<URL> {
8
+ if (typeof group === 'string') {
9
+ return [new URL(group, origin)];
10
+ }
11
+
12
+ return group.pages.flatMap((pageOrGroup: string | NavigationEntry) => {
13
+ if (typeof pageOrGroup === 'string') {
14
+ return new URL(pageOrGroup, origin);
15
+ }
16
+ return recurseOverGroup(pageOrGroup, origin);
17
+ });
18
+ }
@@ -0,0 +1,82 @@
1
+ import { NavigationEntry } from '@mintlify/models';
2
+ import type { Element } from 'hast';
3
+ import { EXIT, visit } from 'unist-util-visit';
4
+
5
+ import { dedupedAppend } from '../utils/append.js';
6
+ import { framework } from '../utils/detectFramework.js';
7
+ import { findFirstChild } from '../utils/firstChild.js';
8
+ import { removeTrailingSlash } from '../utils/strings.js';
9
+ import { getText } from '../utils/text.js';
10
+ import { retrieveNavItems } from './retrieve.js';
11
+
12
+ export type ListItemOptions = {
13
+ sectionTagName: string;
14
+ childListTagName: string;
15
+ title?: string;
16
+ };
17
+
18
+ export function processListItem(
19
+ node: Element,
20
+ opts: ListItemOptions = {
21
+ sectionTagName: 'div',
22
+ childListTagName: 'ul',
23
+ title: undefined,
24
+ }
25
+ ): NavigationEntry | undefined {
26
+ const link = findFirstChild(node, 'a');
27
+ if (!link) return undefined;
28
+
29
+ let linkHref: string | undefined = undefined;
30
+ linkHref = link.properties.href as string | undefined;
31
+
32
+ if (linkHref === undefined || linkHref === '#') {
33
+ return undefined;
34
+ }
35
+
36
+ let isApiReferenceLink = false;
37
+ visit(link, 'element', function (subNode) {
38
+ if (
39
+ subNode.tagName === 'span' &&
40
+ Array.isArray(subNode.properties.className) &&
41
+ subNode.properties.className.includes('rm-APIMethod')
42
+ ) {
43
+ isApiReferenceLink = true;
44
+ return EXIT;
45
+ }
46
+ });
47
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
48
+ if (isApiReferenceLink) return undefined;
49
+
50
+ if (linkHref.startsWith('/')) linkHref = linkHref.substring(1);
51
+
52
+ const sectionHeader = findFirstChild(node, opts.sectionTagName);
53
+ const childList = findFirstChild(node, opts.childListTagName);
54
+ let title = opts.title;
55
+ if (!title) {
56
+ title = getText(link) || getText(sectionHeader) || '';
57
+ if (framework.vendor === 'readme') {
58
+ title = getText(sectionHeader) || getText(link) || '';
59
+ }
60
+ }
61
+
62
+ if (!childList) {
63
+ return linkHref;
64
+ }
65
+
66
+ let childEntries = retrieveNavItems(childList);
67
+ const newLink = childEntries.find(
68
+ (child) => typeof child === 'string' && child.startsWith(linkHref)
69
+ )
70
+ ? removeTrailingSlash(linkHref) + '/mintie_overview'
71
+ : linkHref;
72
+
73
+ if (childEntries.includes(linkHref)) {
74
+ childEntries.forEach((child, index) => {
75
+ if (child === linkHref) childEntries[index] = newLink;
76
+ });
77
+ } else {
78
+ childEntries = dedupedAppend(newLink, childEntries, true);
79
+ }
80
+
81
+ return { group: title, pages: dedupedAppend(newLink, childEntries, true) };
82
+ }
@@ -0,0 +1,88 @@
1
+ import { NavigationEntry } from '@mintlify/models';
2
+ import type { Element } from 'hast';
3
+ import { visit, CONTINUE, SKIP } from 'unist-util-visit';
4
+
5
+ import { framework } from '../utils/detectFramework.js';
6
+ import { findTitle } from '../utils/title.js';
7
+ import { processListItem } from './listItems.js';
8
+
9
+ export function retrieveNavItems(rootNode: Element): Array<NavigationEntry> {
10
+ const result: Array<NavigationEntry> = [];
11
+
12
+ let rootSectionTagName = 'li';
13
+ switch (framework.vendor) {
14
+ case 'docusaurus':
15
+ rootSectionTagName = 'li';
16
+ break;
17
+ case 'gitbook':
18
+ rootSectionTagName = 'li';
19
+ break;
20
+ case 'readme':
21
+ rootSectionTagName = 'section';
22
+ break;
23
+ }
24
+
25
+ let innerSectionTagName = 'div';
26
+ switch (framework.vendor) {
27
+ case 'docusaurus':
28
+ innerSectionTagName = 'li';
29
+ break;
30
+ case 'gitbook':
31
+ innerSectionTagName = 'div';
32
+ break;
33
+ case 'readme':
34
+ innerSectionTagName = 'h2';
35
+ break;
36
+ }
37
+
38
+ visit(rootNode, 'element', function (node, index, parent) {
39
+ if (node.tagName === rootSectionTagName) node.tagName = 'li';
40
+ if (node.tagName !== 'li') return CONTINUE;
41
+
42
+ let title: string | undefined = undefined;
43
+ if (
44
+ node.children[0] &&
45
+ node.children[1] &&
46
+ node.children[1].type === 'element' &&
47
+ node.children[1].tagName === 'ul' &&
48
+ node.children[0].type === 'element' &&
49
+ node.children[0].tagName === 'div' &&
50
+ node.children[0].children.filter((child) => child.type === 'text').length ===
51
+ node.children[0].children.length
52
+ )
53
+ title = findTitle(node.children[0], { delete: false });
54
+
55
+ if (
56
+ framework.vendor === 'readme' &&
57
+ node.children.length === 2 &&
58
+ node.children[1] &&
59
+ node.children[1].type === 'element' &&
60
+ node.children[1].tagName === 'ul' &&
61
+ typeof index === 'number' &&
62
+ parent
63
+ ) {
64
+ node.children = [
65
+ {
66
+ type: 'element',
67
+ tagName: 'div',
68
+ properties: {},
69
+ children: node.children,
70
+ },
71
+ ];
72
+ }
73
+
74
+ const entry = processListItem(node, {
75
+ sectionTagName: innerSectionTagName,
76
+ childListTagName: 'ul',
77
+ title,
78
+ });
79
+
80
+ if (entry !== undefined) {
81
+ result.push(entry);
82
+ return SKIP;
83
+ }
84
+ return CONTINUE;
85
+ });
86
+
87
+ return result;
88
+ }
@@ -0,0 +1,47 @@
1
+ import type { Root as HastRoot, Element } from 'hast';
2
+ import { visit, EXIT } from 'unist-util-visit';
3
+
4
+ import { framework } from '../utils/detectFramework.js';
5
+
6
+ export function retrieveRootNavElement(rootNode: HastRoot): Element | undefined {
7
+ let rootTagName = 'aside';
8
+ switch (framework.vendor) {
9
+ case 'docusaurus':
10
+ rootTagName = 'nav';
11
+ break;
12
+ case 'gitbook':
13
+ rootTagName = 'aside';
14
+ break;
15
+ case 'readme':
16
+ rootTagName = 'nav';
17
+ break;
18
+ }
19
+
20
+ let rootSelector = 'page-no-toc:hidden';
21
+ switch (framework.vendor) {
22
+ case 'docusaurus':
23
+ rootSelector = 'menu';
24
+ break;
25
+ case 'gitbook':
26
+ rootSelector = 'page-no-toc:hidden';
27
+ break;
28
+ case 'readme':
29
+ rootSelector = 'rm-Sidebar';
30
+ break;
31
+ }
32
+
33
+ let element: Element | undefined = undefined;
34
+ visit(rootNode, 'element', function (node) {
35
+ if (
36
+ node.tagName === rootTagName &&
37
+ node.properties.className &&
38
+ Array.isArray(node.properties.className) &&
39
+ node.properties.className.includes(rootSelector)
40
+ ) {
41
+ element = node;
42
+ return EXIT;
43
+ }
44
+ });
45
+
46
+ return element;
47
+ }
@@ -39,13 +39,28 @@ export const generateOpenApiPages = async (
39
39
 
40
40
  const { errors, schema, valid, version } = await validate(pathOrDocument);
41
41
 
42
+ if (!version || version === '2.0') throw new Error('OpenAPI versions prior to 3.0 not supported');
43
+
42
44
  if (!valid) {
43
- const errorMessages = errors ? errors.map((error) => `\n${error.code}: ${error.message}`) : '';
45
+ const errorMessages = errors
46
+ ? errors
47
+ .map((error) => {
48
+ const path =
49
+ 'path' in error
50
+ ? String(error.path)
51
+ .replace('/paths/', '')
52
+ .replaceAll('~1', '/')
53
+ .replaceAll('~2', '~')
54
+ : 'Unknown path';
55
+ return `${path}: ${error.message}`;
56
+ })
57
+ .join('\n')
58
+ : 'An unknown error occurred when trying to validate your OpenAPI spec. Please pass it through an OpenAPI validator and try again.';
59
+ console.error(errorMessages);
44
60
  throw new Error(`Failed to validate OpenAPI schema:${errorMessages}`);
45
61
  }
46
62
 
47
63
  if (!schema) throw new Error('Schema failed to validate. Please try again.');
48
- if (!version || version === '2.0') throw new Error('OpenAPI versions prior to 3.0 not supported');
49
64
 
50
65
  if (schema.paths === undefined || Object.keys(schema.paths).length === 0) {
51
66
  throw new Error('No paths defined.');
@@ -152,8 +167,8 @@ const createOpenApiFrontmatter = async (
152
167
  path: string
153
168
  ) => {
154
169
  const data = `---
155
- openapi: ${method} ${path}
156
- ---`;
170
+ openapi: ${method} ${path}
171
+ ---`;
157
172
 
158
173
  await outputFile(filename, data);
159
174
  };
@@ -0,0 +1,52 @@
1
+ import type { Root as HastRoot, Element } from 'hast';
2
+ import { visit, EXIT } from 'unist-util-visit';
3
+
4
+ import { framework } from '../utils/detectFramework.js';
5
+
6
+ export function retrieveRootContent(rootNode: HastRoot): Element | undefined {
7
+ let rootTagName = 'main';
8
+ switch (framework.vendor) {
9
+ case 'docusaurus':
10
+ rootTagName = 'article';
11
+ break;
12
+ case 'gitbook':
13
+ rootTagName = 'main';
14
+ break;
15
+ case 'readme':
16
+ rootTagName = 'section';
17
+ break;
18
+ }
19
+
20
+ let rootSelector = 'break-anywhere';
21
+ switch (framework.vendor) {
22
+ case 'docusaurus':
23
+ rootSelector = '';
24
+ break;
25
+ case 'gitbook':
26
+ rootSelector = '';
27
+ break;
28
+ case 'readme':
29
+ rootSelector = 'content-body';
30
+ break;
31
+ }
32
+
33
+ let element: Element | undefined = undefined;
34
+ visit(rootNode, 'element', function (node) {
35
+ if (node.tagName === rootTagName) {
36
+ if (rootSelector) {
37
+ if (
38
+ node.properties.className &&
39
+ Array.isArray(node.properties.className) &&
40
+ node.properties.className.includes(rootSelector)
41
+ ) {
42
+ element = node;
43
+ }
44
+ } else {
45
+ element = node;
46
+ return EXIT;
47
+ }
48
+ }
49
+ });
50
+
51
+ return element;
52
+ }
@@ -0,0 +1,62 @@
1
+ import type { Browser } from 'puppeteer';
2
+
3
+ import type { Result } from '../types/result.js';
4
+ import { getErrorMessage } from '../utils/errors.js';
5
+ import { log } from '../utils/log.js';
6
+ import { fetchPageHtml, startPuppeteer } from '../utils/network.js';
7
+ import { scrapePage } from './page.js';
8
+
9
+ export async function scrapePageGroup(
10
+ navGroup: Array<URL>,
11
+ needsBrowser: boolean,
12
+ opts: {
13
+ externalLinks: boolean;
14
+ rootPaths?: Array<string>;
15
+ } = { externalLinks: false }
16
+ ): Promise<Array<Result<[string, string]>>> {
17
+ const browser: Browser | undefined = needsBrowser ? await startPuppeteer() : undefined;
18
+
19
+ try {
20
+ const res = await Promise.all(
21
+ navGroup.map(async (url, index) => {
22
+ try {
23
+ if (opts.externalLinks) {
24
+ const res = scrapePage(`external-link-${index}`, url, { externalLink: true });
25
+ return res;
26
+ }
27
+
28
+ let isOverviewPage = false;
29
+ if (url.toString().endsWith('/mintie_overview')) {
30
+ isOverviewPage = true;
31
+ url = new URL(url.toString().replace('/mintie_overview', ''));
32
+ }
33
+
34
+ const html = await fetchPageHtml(url, browser);
35
+ const res = scrapePage(html, url, {
36
+ externalLink: false,
37
+ isOverviewPage,
38
+ rootPath: opts.rootPaths ? opts.rootPaths[index] : undefined,
39
+ });
40
+ return res;
41
+ } catch (error) {
42
+ const errorMessage = getErrorMessage(error);
43
+ throw new Error(`We encountered an error when scraping ${url}${errorMessage}`);
44
+ }
45
+ })
46
+ );
47
+ return res;
48
+ } catch (error) {
49
+ const errorMessage = getErrorMessage(error);
50
+ log(
51
+ `We encountered an error when scraping the page group from ${
52
+ navGroup[0]?.origin ?? 'the URL provided'
53
+ }${errorMessage}`
54
+ );
55
+ console.error(error);
56
+ throw error;
57
+ } finally {
58
+ if (browser) {
59
+ await browser.close();
60
+ }
61
+ }
62
+ }
@@ -0,0 +1,26 @@
1
+ import type { Root as HastRoot } from 'hast';
2
+ import { EXIT, visit } from 'unist-util-visit';
3
+
4
+ import { downloadImage } from '../utils/images.js';
5
+
6
+ export async function downloadFavicon(hast: HastRoot): Promise<string | undefined> {
7
+ let src: string = '';
8
+ visit(hast, 'element', function (node) {
9
+ if (
10
+ node.tagName === 'link' &&
11
+ typeof node.properties.rel === 'string' &&
12
+ (node.properties.rel === 'icon' || node.properties.rel === 'shortcut icon')
13
+ ) {
14
+ src = node.properties.href as string;
15
+ return EXIT;
16
+ }
17
+ });
18
+
19
+ if (!src) return undefined;
20
+
21
+ const res = await downloadImage(src, process.cwd());
22
+ if (!res.success) return undefined;
23
+ if (!res.data) return undefined;
24
+
25
+ return res.data[1];
26
+ }
@@ -0,0 +1,67 @@
1
+ import type { Root as MdastRoot } from 'mdast';
2
+ import type { MdxJsxAttribute } from 'mdast-util-mdx-jsx';
3
+ import { join, dirname } from 'node:path';
4
+ import { CONTINUE, visit } from 'unist-util-visit';
5
+
6
+ import type { Result } from '../types/result.js';
7
+ import { downloadImage } from '../utils/images.js';
8
+ import { createFilename } from '../utils/path.js';
9
+
10
+ export async function downloadImagesFromFile(
11
+ root: MdastRoot,
12
+ url: string | URL
13
+ ): Promise<Array<Result<[string, string]>>> {
14
+ url = new URL(url);
15
+ const imageUrls: Array<string> = [];
16
+
17
+ visit(root, function (node) {
18
+ let imageUrl: string | undefined = undefined;
19
+ if (node.type === 'image') {
20
+ imageUrl = node.url;
21
+ } else if (node.type === 'mdxJsxFlowElement') {
22
+ imageUrl = node.attributes.find(
23
+ (attr) => attr.type === 'mdxJsxAttribute' && (attr.name === 'src' || attr.name === 'img')
24
+ )?.value as string | undefined;
25
+ }
26
+
27
+ if (!imageUrl) return CONTINUE;
28
+
29
+ if (imageUrl.startsWith('/')) {
30
+ imageUrl = new URL(imageUrl, url.origin).toString();
31
+ }
32
+ imageUrls.push(imageUrl);
33
+ });
34
+
35
+ const rootPath = join(process.cwd(), '/images');
36
+ const filename = createFilename(rootPath, url, '');
37
+ const localRootPath = filename ? dirname(filename) : rootPath;
38
+
39
+ const imageResults = await Promise.all(
40
+ imageUrls.map(async (imageUrl) => {
41
+ const result = await downloadImage(imageUrl, localRootPath);
42
+ return result;
43
+ })
44
+ );
45
+
46
+ const imagePathsMap = new Map<string, string>(
47
+ imageResults.filter((result) => result.success).map((result) => result.data as [string, string])
48
+ );
49
+
50
+ visit(root, function (node, index, parent) {
51
+ if (node.type === 'image') {
52
+ node.url = imagePathsMap.get(node.url) ?? node.url;
53
+ if (parent && typeof index === 'number') parent.children[index] = node;
54
+ } else if (node.type === 'mdxJsxFlowElement') {
55
+ const urlAttr = (node.attributes as Array<MdxJsxAttribute>).find(
56
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
57
+ (attr) => attr.type === 'mdxJsxAttribute' && (attr.name === 'src' || attr.name === 'img')
58
+ );
59
+ if (!urlAttr) return CONTINUE;
60
+
61
+ urlAttr.value = imagePathsMap.get(urlAttr.value as string) ?? urlAttr.value;
62
+ if (parent && typeof index === 'number') parent.children[index] = node;
63
+ }
64
+ });
65
+
66
+ return imageResults;
67
+ }
@@ -0,0 +1,127 @@
1
+ import type { Root as HastRoot, Element } from 'hast';
2
+ import { join } from 'node:path';
3
+ import { Browser } from 'puppeteer';
4
+ import { EXIT, visit } from 'unist-util-visit';
5
+
6
+ import { framework } from '../utils/detectFramework.js';
7
+ import { downloadImage } from '../utils/images.js';
8
+ import { fetchPageHtml } from '../utils/network.js';
9
+ import { htmlToHast } from './root.js';
10
+
11
+ function findReadmeLogoNodes(root: HastRoot): Array<Element> | undefined {
12
+ const elements: Array<Element> = [];
13
+ visit(root, 'element', function (node) {
14
+ if (
15
+ node.tagName === 'img' &&
16
+ Array.isArray(node.properties.className) &&
17
+ node.properties.className.includes('rm-Logo-img')
18
+ )
19
+ elements.push(node);
20
+ });
21
+ return elements.length ? elements : undefined;
22
+ }
23
+
24
+ function findGitBookLogoNodes(root: HastRoot): Array<Element> | undefined {
25
+ const elements: Array<Element> = [];
26
+ visit(root, 'element', function (node) {
27
+ if (node.tagName === 'img' && node.properties.alt === 'Logo') {
28
+ elements.push(node);
29
+ }
30
+ });
31
+ return elements.length ? elements : undefined;
32
+ }
33
+
34
+ function findDocusaurusLogoNodes(root: HastRoot): Array<Element> | undefined {
35
+ const elements: Array<Element> = [];
36
+ visit(root, 'element', function (node) {
37
+ if (
38
+ node.tagName === 'div' &&
39
+ Array.isArray(node.properties.className) &&
40
+ node.properties.className.includes('navbar__brand')
41
+ ) {
42
+ visit(node, 'element', function (subNode) {
43
+ if (subNode.tagName === 'img') elements.push(subNode);
44
+ });
45
+ return EXIT;
46
+ }
47
+ });
48
+ return elements.length ? elements : undefined;
49
+ }
50
+
51
+ async function findLogosFromHtml(
52
+ html: string,
53
+ downloadFn: (root: HastRoot) => Array<Element> | undefined,
54
+ filepaths: Array<string>
55
+ ) {
56
+ const hast = htmlToHast(html);
57
+ const imgNodes = downloadFn(hast);
58
+
59
+ if (imgNodes) {
60
+ filepaths.push(
61
+ ...(await Promise.all(
62
+ imgNodes.map(async (node) => {
63
+ const res = await downloadImage(
64
+ node.properties.src as string,
65
+ join(process.cwd(), 'images')
66
+ );
67
+
68
+ if (res.success && res.data) {
69
+ return res.data[1];
70
+ } else {
71
+ return '';
72
+ }
73
+ })
74
+ ))
75
+ );
76
+ }
77
+
78
+ filepaths.forEach((filepath, index) => {
79
+ if (!filepath) filepaths.splice(index, 1);
80
+ });
81
+ }
82
+
83
+ export async function downloadLogos(
84
+ url: string | URL,
85
+ browser: Browser | undefined
86
+ ): Promise<string | { light: string; dark: string } | undefined> {
87
+ url = new URL(url);
88
+ const filepaths: Array<string> = [];
89
+ if (browser) {
90
+ const htmls: Array<string> = [];
91
+
92
+ const page = await browser.newPage();
93
+ await page.goto(url.toString(), {
94
+ waitUntil: 'networkidle2',
95
+ });
96
+
97
+ htmls.push(await page.content());
98
+ await page.click('.rm-ThemeToggle');
99
+ htmls.push(await page.content());
100
+
101
+ await Promise.all(
102
+ htmls.map(async (html) => {
103
+ return await findLogosFromHtml(html, findReadmeLogoNodes, filepaths);
104
+ })
105
+ );
106
+ } else {
107
+ const html = await fetchPageHtml(url);
108
+ await findLogosFromHtml(
109
+ html,
110
+ framework.vendor === 'gitbook' ? findGitBookLogoNodes : findDocusaurusLogoNodes,
111
+ filepaths
112
+ );
113
+ }
114
+
115
+ if (browser) await browser.close();
116
+
117
+ const uniqueFilepaths = [...new Set(filepaths).values()];
118
+
119
+ return uniqueFilepaths.length === 1
120
+ ? uniqueFilepaths[0]
121
+ : uniqueFilepaths.length > 1
122
+ ? {
123
+ light: uniqueFilepaths[0] as string,
124
+ dark: uniqueFilepaths[1] as string,
125
+ }
126
+ : undefined;
127
+ }