@mintlify/scraping 3.0.14 → 3.0.16
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/.prettierrc +1 -0
- package/bin/browser.js +3 -3
- package/bin/constants.js +23 -23
- package/bin/constants.js.map +1 -1
- package/bin/downloadImage.js +18 -18
- package/bin/downloadImage.js.map +1 -1
- package/bin/scraping/detectFramework.js +13 -13
- package/bin/scraping/detectFramework.js.map +1 -1
- package/bin/scraping/downloadAllImages.js +5 -5
- package/bin/scraping/downloadAllImages.js.map +1 -1
- package/bin/scraping/downloadLogoImage.js +4 -4
- package/bin/scraping/downloadLogoImage.js.map +1 -1
- package/bin/scraping/getSitemapLinks.js +4 -4
- package/bin/scraping/scrapeFileGettingFileNameFromUrl.js +10 -10
- package/bin/scraping/scrapeFileGettingFileNameFromUrl.js.map +1 -1
- package/bin/scraping/scrapeGettingFileNameFromUrl.js +2 -2
- package/bin/scraping/scrapeGettingFileNameFromUrl.js.map +1 -1
- package/bin/scraping/scrapePage.js +3 -3
- package/bin/scraping/scrapePage.js.map +1 -1
- package/bin/scraping/scrapePageCommands.d.ts +1 -1
- package/bin/scraping/scrapePageCommands.js +15 -15
- package/bin/scraping/scrapePageCommands.js.map +1 -1
- package/bin/scraping/scrapeSection.js +6 -6
- package/bin/scraping/scrapeSection.js.map +1 -1
- package/bin/scraping/scrapeSectionCommands.d.ts +1 -1
- package/bin/scraping/scrapeSectionCommands.js +14 -14
- package/bin/scraping/scrapeSectionCommands.js.map +1 -1
- package/bin/scraping/site-scrapers/Intercom/scrapeIntercomPage.js +11 -11
- package/bin/scraping/site-scrapers/Intercom/scrapeIntercomPage.js.map +1 -1
- package/bin/scraping/site-scrapers/Intercom/scrapeIntercomSection.js +12 -14
- package/bin/scraping/site-scrapers/Intercom/scrapeIntercomSection.js.map +1 -1
- package/bin/scraping/site-scrapers/alternateGroupTitle.js +1 -1
- package/bin/scraping/site-scrapers/links-per-group/getDocusaurusLinksPerGroup.js +8 -11
- package/bin/scraping/site-scrapers/links-per-group/getDocusaurusLinksPerGroup.js.map +1 -1
- package/bin/scraping/site-scrapers/links-per-group/getLinksRecursively.js +6 -6
- package/bin/scraping/site-scrapers/links-per-group/getLinksRecursivelyGitBook.js +4 -4
- package/bin/scraping/site-scrapers/openNestedDocusaurusMenus.d.ts +1 -1
- package/bin/scraping/site-scrapers/openNestedDocusaurusMenus.js +4 -4
- package/bin/scraping/site-scrapers/openNestedGitbookMenus.d.ts +1 -1
- package/bin/scraping/site-scrapers/openNestedGitbookMenus.js.map +1 -1
- package/bin/scraping/site-scrapers/scrapeDocusaurusPage.js +14 -14
- package/bin/scraping/site-scrapers/scrapeDocusaurusPage.js.map +1 -1
- package/bin/scraping/site-scrapers/scrapeDocusaurusSection.js +9 -9
- package/bin/scraping/site-scrapers/scrapeDocusaurusSection.js.map +1 -1
- package/bin/scraping/site-scrapers/scrapeGitBookPage.js +12 -14
- package/bin/scraping/site-scrapers/scrapeGitBookPage.js.map +1 -1
- package/bin/scraping/site-scrapers/scrapeGitBookSection.js +10 -15
- package/bin/scraping/site-scrapers/scrapeGitBookSection.js.map +1 -1
- package/bin/scraping/site-scrapers/scrapeReadMePage.js +15 -15
- package/bin/scraping/site-scrapers/scrapeReadMePage.js.map +1 -1
- package/bin/scraping/site-scrapers/scrapeReadMeSection.js +11 -15
- package/bin/scraping/site-scrapers/scrapeReadMeSection.js.map +1 -1
- package/bin/tsconfig.tsbuildinfo +1 -1
- package/bin/util.d.ts +1 -1
- package/bin/util.js +23 -26
- package/bin/util.js.map +1 -1
- package/bin/validation/stopIfInvalidLink.js +3 -3
- package/package.json +9 -9
- package/src/browser.ts +3 -3
- package/src/constants.ts +23 -23
- package/src/downloadImage.ts +21 -26
- package/src/scraping/detectFramework.ts +18 -18
- package/src/scraping/downloadAllImages.ts +7 -9
- package/src/scraping/downloadLogoImage.ts +5 -4
- package/src/scraping/getSitemapLinks.ts +4 -4
- package/src/scraping/scrapeFileGettingFileNameFromUrl.ts +12 -18
- package/src/scraping/scrapeGettingFileNameFromUrl.ts +7 -5
- package/src/scraping/scrapePage.ts +4 -3
- package/src/scraping/scrapePageCommands.ts +17 -18
- package/src/scraping/scrapeSection.ts +8 -16
- package/src/scraping/scrapeSectionCommands.ts +19 -34
- package/src/scraping/site-scrapers/Intercom/scrapeIntercomPage.ts +12 -11
- package/src/scraping/site-scrapers/Intercom/scrapeIntercomSection.ts +23 -24
- package/src/scraping/site-scrapers/alternateGroupTitle.ts +1 -1
- package/src/scraping/site-scrapers/links-per-group/getDocusaurusLinksPerGroup.ts +8 -11
- package/src/scraping/site-scrapers/links-per-group/getLinksRecursively.ts +6 -6
- package/src/scraping/site-scrapers/links-per-group/getLinksRecursivelyGitBook.ts +4 -4
- package/src/scraping/site-scrapers/openNestedDocusaurusMenus.ts +5 -5
- package/src/scraping/site-scrapers/openNestedGitbookMenus.ts +2 -4
- package/src/scraping/site-scrapers/scrapeDocusaurusPage.ts +15 -18
- package/src/scraping/site-scrapers/scrapeDocusaurusSection.ts +11 -14
- package/src/scraping/site-scrapers/scrapeGitBookPage.ts +13 -14
- package/src/scraping/site-scrapers/scrapeGitBookSection.ts +11 -15
- package/src/scraping/site-scrapers/scrapeReadMePage.ts +17 -22
- package/src/scraping/site-scrapers/scrapeReadMeSection.ts +27 -31
- package/src/util.ts +25 -36
- package/src/validation/stopIfInvalidLink.ts +3 -3
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import cheerio from
|
|
2
|
-
import { NodeHtmlMarkdown } from
|
|
3
|
-
import downloadAllImages from
|
|
4
|
-
import replaceImagePaths from
|
|
1
|
+
import cheerio from 'cheerio';
|
|
2
|
+
import { NodeHtmlMarkdown } from 'node-html-markdown';
|
|
3
|
+
import downloadAllImages from '../../downloadAllImages.js';
|
|
4
|
+
import replaceImagePaths from '../../replaceImagePaths.js';
|
|
5
5
|
export async function scrapeIntercomPage(html, origin, cliDir, imageBaseDir, overwrite, _ // version
|
|
6
6
|
) {
|
|
7
7
|
const $ = cheerio.load(html);
|
|
8
|
-
const titleComponent = $(
|
|
8
|
+
const titleComponent = $('.t__h1').first();
|
|
9
9
|
const title = titleComponent.text().trim();
|
|
10
|
-
const description = $(
|
|
11
|
-
const content = $(
|
|
10
|
+
const description = $('.article__desc', titleComponent.parent()).text().trim();
|
|
11
|
+
const content = $('article').first();
|
|
12
12
|
const contentHtml = $.html(content);
|
|
13
13
|
const origToWritePath = await downloadAllImages($, content, origin, imageBaseDir, overwrite, undefined);
|
|
14
14
|
const nhm = new NodeHtmlMarkdown({ useInlineLinks: false });
|
|
15
15
|
let markdown = nhm.translate(contentHtml);
|
|
16
16
|
// Keep headers on one line
|
|
17
|
-
markdown = markdown.replace(/# \n\n/g,
|
|
17
|
+
markdown = markdown.replace(/# \n\n/g, '# ');
|
|
18
18
|
// Remove unnecessary nonwidth blank space characters
|
|
19
|
-
markdown = markdown.replace(/\u200b/g,
|
|
19
|
+
markdown = markdown.replace(/\u200b/g, '');
|
|
20
20
|
// Reduce unnecessary blank lines
|
|
21
|
-
markdown = markdown.replace(/\n\n\n/g,
|
|
21
|
+
markdown = markdown.replace(/\n\n\n/g, '\n\n');
|
|
22
22
|
// Mintlify doesn't support bolded headers, remove the asterisks
|
|
23
|
-
markdown = markdown.replace(/(\n#+) \*\*(.*)\*\*\n/g,
|
|
23
|
+
markdown = markdown.replace(/(\n#+) \*\*(.*)\*\*\n/g, '$1 $2\n');
|
|
24
24
|
if (origToWritePath) {
|
|
25
25
|
markdown = replaceImagePaths(origToWritePath, cliDir, markdown);
|
|
26
26
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scrapeIntercomPage.js","sourceRoot":"","sources":["../../../../src/scraping/site-scrapers/Intercom/scrapeIntercomPage.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"scrape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E7C,qDAAqD;IACrD,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;IAE3C,iCAAiC;IACjC,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IAE/C,gEAAgE;IAChE,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,wBAAwB,EAAE,SAAS,CAAC,CAAC;IACjE,IAAI,eAAe,EAAE;QACnB,QAAQ,GAAG,iBAAiB,CAAC,eAAe,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;KACjE;IAED,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC;AAC1C,CAAC"}
|
|
@@ -1,24 +1,22 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import cheerio from 'cheerio';
|
|
3
|
+
import downloadLogoImage from '../../downloadLogoImage.js';
|
|
4
|
+
import { scrapeGettingFileNameFromUrl } from '../../scrapeGettingFileNameFromUrl.js';
|
|
5
|
+
import { scrapeIntercomPage } from './scrapeIntercomPage.js';
|
|
6
6
|
export async function scrapeIntercomSection(html, origin, cliDir, imageBaseDir, overwrite, version) {
|
|
7
7
|
let $ = cheerio.load(html);
|
|
8
|
-
const logoSrc = $(
|
|
8
|
+
const logoSrc = $('.header__logo img').first().attr('src');
|
|
9
9
|
downloadLogoImage(logoSrc, imageBaseDir, origin, overwrite);
|
|
10
|
-
const collectionsLink = $(
|
|
11
|
-
const collectionsMap = collectionsLink
|
|
12
|
-
.
|
|
13
|
-
.map(async (s) => {
|
|
14
|
-
const href = $(s).attr("href");
|
|
10
|
+
const collectionsLink = $('.section .g__space a');
|
|
11
|
+
const collectionsMap = collectionsLink.toArray().map(async (s) => {
|
|
12
|
+
const href = $(s).attr('href');
|
|
15
13
|
const res = await axios.get(`${origin}${href}`);
|
|
16
14
|
const html = res.data;
|
|
17
15
|
$ = cheerio.load(html);
|
|
18
|
-
const sectionTitle = $(
|
|
19
|
-
const sectionPages = $(
|
|
16
|
+
const sectionTitle = $('.collection h1').first().text().trim();
|
|
17
|
+
const sectionPages = $('.section .g__space a')
|
|
20
18
|
.toArray()
|
|
21
|
-
.map((s) => $(s).attr(
|
|
19
|
+
.map((s) => $(s).attr('href'))
|
|
22
20
|
.filter((page) => page !== undefined);
|
|
23
21
|
return {
|
|
24
22
|
group: sectionTitle,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scrapeIntercomSection.js","sourceRoot":"","sources":["../../../../src/scraping/site-scrapers/Intercom/scrapeIntercomSection.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"scrapeIntercomSection.js","sourceRoot":"","sources":["../../../../src/scraping/site-scrapers/Intercom/scrapeIntercomSection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,OAAO,MAAM,SAAS,CAAC;AAE9B,OAAO,iBAAiB,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,4BAA4B,EAAE,MAAM,uCAAuC,CAAC;AACrF,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7D,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,IAAY,EACZ,MAAc,EACd,MAAc,EACd,YAAoB,EACpB,SAAkB,EAClB,OAA2B;IAE3B,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAE3B,MAAM,OAAO,GAAG,CAAC,CAAC,mBAAmB,CAAC,CAAC,KAAK,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC3D,iBAAiB,CAAC,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;IAE5D,MAAM,eAAe,GAAG,CAAC,CAAC,sBA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1
|
-
import alternateGroupTitle from
|
|
2
|
-
import getLinksRecursively from
|
|
1
|
+
import alternateGroupTitle from '../alternateGroupTitle.js';
|
|
2
|
+
import getLinksRecursively from './getLinksRecursively.js';
|
|
3
3
|
export function getDocusaurusLinksPerGroup(navigationSections, $, version) {
|
|
4
|
-
if (version ===
|
|
4
|
+
if (version === '3' || version === '2') {
|
|
5
5
|
return getDocusaurusLinksPerGroupLoop(navigationSections, $);
|
|
6
6
|
}
|
|
7
7
|
return [];
|
|
@@ -10,19 +10,16 @@ function getDocusaurusLinksPerGroupLoop(navigationSections, $) {
|
|
|
10
10
|
return navigationSections.toArray().map((s) => {
|
|
11
11
|
const section = $(s);
|
|
12
12
|
// Links without a group
|
|
13
|
-
if (section.hasClass(
|
|
14
|
-
const linkHref = section.find(
|
|
13
|
+
if (section.hasClass('theme-doc-sidebar-item-link')) {
|
|
14
|
+
const linkHref = section.find('a[href]').first().attr('href');
|
|
15
15
|
return {
|
|
16
|
-
group:
|
|
16
|
+
group: '',
|
|
17
17
|
pages: [linkHref],
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
|
-
const firstLink = section
|
|
21
|
-
.find(".menu__list-item-collapsible")
|
|
22
|
-
.first()
|
|
23
|
-
.find("a[href]");
|
|
20
|
+
const firstLink = section.find('.menu__list-item-collapsible').first().find('a[href]');
|
|
24
21
|
const sectionTitle = firstLink.text();
|
|
25
|
-
const firstHref = firstLink.attr(
|
|
22
|
+
const firstHref = firstLink.attr('href');
|
|
26
23
|
const linkSections = section.children().eq(1).children();
|
|
27
24
|
const pages = getLinksRecursively(linkSections, $);
|
|
28
25
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getDocusaurusLinksPerGroup.js","sourceRoot":"","sources":["../../../../src/scraping/site-scrapers/links-per-group/getDocusaurusLinksPerGroup.ts"],"names":[],"mappings":"AAAA,OAAO,mBAAmB,MAAM,2BAA2B,CAAC;AAC5D,OAAO,mBAAmB,MAAM,0BAA0B,CAAC;AAE3D,MAAM,UAAU,0BAA0B,CACxC,kBAAuB,EACvB,CAAM,EACN,OAA2B;IAE3B,IAAI,OAAO,KAAK,GAAG,IAAI,OAAO,KAAK,GAAG,EAAE;QACtC,OAAO,8BAA8B,CAAC,kBAAkB,EAAE,CAAC,CAAC,CAAC;KAC9D;IACD,OAAO,EAAE,CAAC;AACZ,CAAC;AAED,SAAS,8BAA8B,CAAC,kBAAuB,EAAE,CAAM;IACrE,OAAO,kBAAkB,CAAC,OAAO,EAAE,CAAC,GAAG,CAAC,CAAC,CAAS,EAAE,EAAE;QACpD,MAAM,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QAErB,wBAAwB;QACxB,IAAI,OAAO,CAAC,QAAQ,CAAC,6BAA6B,CAAC,EAAE;YACnD,MAAM,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,KAAK,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YAC9D,OAAO;gBACL,KAAK,EAAE,EAAE;gBACT,KAAK,EAAE,CAAC,QAAQ,CAAC;aAClB,CAAC;SACH;QAED,MAAM,SAAS,GAAG,OAAO
|
|
1
|
+
{"version":3,"file":"getDocusaurusLinksPerGroup.js","sourceRoot":"","sources":["../../../../src/scraping/site-scrapers/links-per-group/getDocusaurusLinksPerGroup.ts"],"names":[],"mappings":"AAAA,OAAO,mBAAmB,MAAM,2BAA2B,CAAC;AAC5D,OAAO,mBAAmB,MAAM,0BAA0B,CAAC;AAE3D,MAAM,UAAU,0BAA0B,CACxC,kBAAuB,EACvB,CAAM,EACN,OAA2B;IAE3B,IAAI,OAAO,KAAK,GAAG,IAAI,OAAO,KAAK,GAAG,EAAE;QACtC,OAAO,8BAA8B,CAAC,kBAAkB,EAAE,CAAC,CAAC,CAAC;KAC9D;IACD,OAAO,EAAE,CAAC;AACZ,CAAC;AAED,SAAS,8BAA8B,CAAC,kBAAuB,EAAE,CAAM;IACrE,OAAO,kBAAkB,CAAC,OAAO,EAAE,CAAC,GAAG,CAAC,CAAC,CAAS,EAAE,EAAE;QACpD,MAAM,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QAErB,wBAAwB;QACxB,IAAI,OAAO,CAAC,QAAQ,CAAC,6BAA6B,CAAC,EAAE;YACnD,MAAM,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,KAAK,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YAC9D,OAAO;gBACL,KAAK,EAAE,EAAE;gBACT,KAAK,EAAE,CAAC,QAAQ,CAAC;aAClB,CAAC;SACH;QAED,MAAM,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC,KAAK,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAEvF,MAAM,YAAY,GAAG,SAAS,CAAC,IAAI,EAAE,CAAC;QACtC,MAAM,SAAS,GAAG,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACzC,MAAM,YAAY,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;QAEzD,MAAM,KAAK,GAAG,mBAAmB,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC;QAEnD,OAAO;YACL,KAAK,EAAE,YAAY,IAAI,mBAAmB,CAAC,SAAS,EAAE,KAAK,CAAC;YAC5D,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK;SACjD,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -7,18 +7,18 @@ export default function getLinksRecursively(linkSections, $) {
|
|
|
7
7
|
.map((i, s) => {
|
|
8
8
|
const subsection = $(s);
|
|
9
9
|
let link = subsection.children().first();
|
|
10
|
-
if (!link.attr(
|
|
10
|
+
if (!link.attr('href')) {
|
|
11
11
|
// Docusaurus nests the <a> inside a <div>
|
|
12
|
-
link = link.find(
|
|
12
|
+
link = link.find('a[href]').first();
|
|
13
13
|
}
|
|
14
|
-
const linkHref = link.attr(
|
|
14
|
+
const linkHref = link.attr('href');
|
|
15
15
|
// Skip missing links. For example, GitBook uses
|
|
16
16
|
// empty divs are used for styling a line beside the nav.
|
|
17
17
|
// Skip external links until Mintlify supports them
|
|
18
18
|
if (!linkHref ||
|
|
19
|
-
linkHref ===
|
|
20
|
-
linkHref.startsWith(
|
|
21
|
-
linkHref.startsWith(
|
|
19
|
+
linkHref === '#' ||
|
|
20
|
+
linkHref.startsWith('https://') ||
|
|
21
|
+
linkHref.startsWith('http://')) {
|
|
22
22
|
return undefined;
|
|
23
23
|
}
|
|
24
24
|
const childLinks = subsection.children().eq(1).children();
|
|
@@ -11,14 +11,14 @@ export default function getLinksRecursivelyGitBook(linkSections, $) {
|
|
|
11
11
|
subsection = subsection.children().first();
|
|
12
12
|
}
|
|
13
13
|
const link = subsection.children().first();
|
|
14
|
-
const linkHref = link.attr(
|
|
14
|
+
const linkHref = link.attr('href');
|
|
15
15
|
// Skip missing links. For example, GitBook uses
|
|
16
16
|
// empty divs are used for styling a line beside the nav.
|
|
17
17
|
// Skip external links until Mintlify supports them
|
|
18
18
|
if (!linkHref ||
|
|
19
|
-
linkHref ===
|
|
20
|
-
linkHref.startsWith(
|
|
21
|
-
linkHref.startsWith(
|
|
19
|
+
linkHref === '#' ||
|
|
20
|
+
linkHref.startsWith('https://') ||
|
|
21
|
+
linkHref.startsWith('http://')) {
|
|
22
22
|
return undefined;
|
|
23
23
|
}
|
|
24
24
|
const childLinks = subsection.children().eq(1).children();
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Page } from
|
|
1
|
+
import { Page } from 'puppeteer';
|
|
2
2
|
export default function openNestedDocusaurusMenus(page: Page): Promise<string>;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
export default async function openNestedDocusaurusMenus(page) {
|
|
2
2
|
let prevEncountered = [];
|
|
3
|
-
let encounteredHref = [
|
|
3
|
+
let encounteredHref = ['fake-href-to-make-loop-run-at-least-once'];
|
|
4
4
|
// Loop until we've encountered every link
|
|
5
5
|
while (!encounteredHref.every((href) => prevEncountered.includes(href))) {
|
|
6
6
|
prevEncountered = encounteredHref;
|
|
7
7
|
encounteredHref = await page.evaluate((encounteredHref) => {
|
|
8
|
-
const collapsible = Array.from(document.querySelectorAll(
|
|
8
|
+
const collapsible = Array.from(document.querySelectorAll('.menu__link.menu__link--sublist'));
|
|
9
9
|
const linksFound = [];
|
|
10
10
|
collapsible.forEach(async (collapsibleItem) => {
|
|
11
|
-
const href = collapsibleItem?.getAttribute(
|
|
11
|
+
const href = collapsibleItem?.getAttribute('href');
|
|
12
12
|
// Should never occur but we keep it as a fail-safe
|
|
13
|
-
if (href?.startsWith(
|
|
13
|
+
if (href?.startsWith('https://') || href?.startsWith('http://')) {
|
|
14
14
|
return;
|
|
15
15
|
}
|
|
16
16
|
// Click any links we haven't seen before
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Page } from
|
|
1
|
+
import { Page } from 'puppeteer';
|
|
2
2
|
export default function openNestedGitbookMenus(page: Page): Promise<string>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openNestedGitbookMenus.js","sourceRoot":"","sources":["../../../src/scraping/site-scrapers/openNestedGitbookMenus.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,sBAAsB,CAAC,IAAU;IAC7D,IAAI,UAAU,GAAG,IAAI,CAAC;IAEtB,iDAAiD;IACjD,OAAO,UAAU,EAAE;QACjB,UAAU,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE;YACpC,yDAAyD;YACzD,MAAM,KAAK,GAAkB,KAAK,CAAC,IAAI,
|
|
1
|
+
{"version":3,"file":"openNestedGitbookMenus.js","sourceRoot":"","sources":["../../../src/scraping/site-scrapers/openNestedGitbookMenus.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,sBAAsB,CAAC,IAAU;IAC7D,IAAI,UAAU,GAAG,IAAI,CAAC;IAEtB,iDAAiD;IACjD,OAAO,UAAU,EAAE;QACjB,UAAU,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE;YACpC,yDAAyD;YACzD,MAAM,KAAK,GAAkB,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,gBAAgB,CAAC,yBAAyB,CAAC,CAAC,CAAC;YAE9F,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,IAAiB,EAAE,EAAE;gBACxC,MAAM,OAAO,GAAG,IAAI,EAAE,aAAa,EAAE,aAAa,CAAC;gBACnD,IAAI,OAAO,EAAE;oBACX,OAAO,CAAC,KAAK,EAAE,CAAC;iBACjB;YACH,CAAC,CAAC,CAAC;YAEH,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;QAC1B,CAAC,CAAC,CAAC;KACJ;IAED,OAAO,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC;AAC9B,CAAC"}
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import cheerio from
|
|
2
|
-
import { NodeHtmlMarkdown } from
|
|
3
|
-
import downloadAllImages from
|
|
4
|
-
import replaceImagePaths from
|
|
1
|
+
import cheerio from 'cheerio';
|
|
2
|
+
import { NodeHtmlMarkdown } from 'node-html-markdown';
|
|
3
|
+
import downloadAllImages from '../downloadAllImages.js';
|
|
4
|
+
import replaceImagePaths from '../replaceImagePaths.js';
|
|
5
5
|
export async function scrapeDocusaurusPage(html, origin, cliDir, imageBaseDir, overwrite, version // expects "2", or "3". Have not written support for "1" yet
|
|
6
6
|
) {
|
|
7
7
|
const $ = cheerio.load(html);
|
|
8
|
-
const article = version ===
|
|
8
|
+
const article = version === '3' ? $('.theme-doc-markdown').first() : $('article').first();
|
|
9
9
|
if (article.length === 0) {
|
|
10
10
|
// Index pages with no additional text don't have the markdown class
|
|
11
11
|
return {
|
|
12
|
-
title: ''
|
|
12
|
+
title: '',
|
|
13
13
|
};
|
|
14
14
|
}
|
|
15
|
-
const titleComponent = article.find(
|
|
15
|
+
const titleComponent = article.find('h1');
|
|
16
16
|
const title = titleComponent.text().trim();
|
|
17
17
|
// Do not include title in the content when we insert it in our metadata
|
|
18
18
|
titleComponent.remove();
|
|
19
|
-
const markdownContent = version ===
|
|
19
|
+
const markdownContent = version === '3' ? article : article.find('.markdown').first();
|
|
20
20
|
const origToWritePath = await downloadAllImages($, markdownContent, origin, imageBaseDir, overwrite);
|
|
21
21
|
const markdownHtml = markdownContent.html();
|
|
22
22
|
const nhm = new NodeHtmlMarkdown({ useInlineLinks: false });
|
|
23
23
|
let markdown = markdownHtml ? nhm.translate(markdownHtml) : null;
|
|
24
24
|
if (markdown == null) {
|
|
25
|
-
console.error(
|
|
26
|
-
return { title, description: undefined, markdown:
|
|
25
|
+
console.error('We do not support scraping this page. Content will be empty');
|
|
26
|
+
return { title, description: undefined, markdown: '' };
|
|
27
27
|
}
|
|
28
28
|
// Description only exists in meta tags. The code is commented out because its prone to incorrectly
|
|
29
29
|
// including a description if the first line of text had markdown annotations like `.
|
|
@@ -38,13 +38,13 @@ export async function scrapeDocusaurusPage(html, origin, cliDir, imageBaseDir, o
|
|
|
38
38
|
// When we parse their HTML the parser adds things like:
|
|
39
39
|
// [](#setup "Direct link to heading")
|
|
40
40
|
// to the end of each header.
|
|
41
|
-
markdown = markdown.replace(/\[\]\(#.+ ".+"\)\n/g,
|
|
41
|
+
markdown = markdown.replace(/\[\]\(#.+ ".+"\)\n/g, '\n');
|
|
42
42
|
// Remove unnecessary nonwidth blank space characters
|
|
43
|
-
markdown = markdown.replace(/\u200b/g,
|
|
43
|
+
markdown = markdown.replace(/\u200b/g, '');
|
|
44
44
|
// Reduce unnecessary blank lines
|
|
45
|
-
markdown = markdown.replace(/\n\n\n/g,
|
|
45
|
+
markdown = markdown.replace(/\n\n\n/g, '\n\n');
|
|
46
46
|
// Mintlify doesn't support bolded headers, remove the asterisks
|
|
47
|
-
markdown = markdown.replace(/(\n#+) \*\*(.*)\*\*\n/g,
|
|
47
|
+
markdown = markdown.replace(/(\n#+) \*\*(.*)\*\*\n/g, '$1 $2\n');
|
|
48
48
|
if (origToWritePath) {
|
|
49
49
|
markdown = replaceImagePaths(origToWritePath, cliDir, markdown);
|
|
50
50
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scrapeDocusaurusPage.js","sourceRoot":"","sources":["../../../src/scraping/site-scrapers/scrapeDocusaurusPage.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"scrapeDocusaurusPage.js","sourceRoot":"","sources":["../../../src/scraping/site-scrapers/scrapeDocusaurusPage.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,OAAO,iBAAiB,MAAM,yBAAyB,CAAC;AACxD,OAAO,iBAAiB,MAAM,yBAAyB,CAAC;AAExD,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,IAAY,EACZ,MAAc,EACd,MAAc,EACd,YAAoB,EACpB,SAAkB,EAClB,OAA2B,CAAC,4DAA4D;;IAMxF,MAAM,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAE7B,MAAM,OAAO,GAAG,OAAO,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,KAAK,EAAE,CAAC;IAE1F,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE;QACxB,oEAAoE;QACpE,OAAO;YACL,KAAK,EAAE,EAAE;SACV,CAAC;KACH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,SAAS,EAAE,EAAE,CAAC,CAAC;IAE3C,iCAAiC;IACjC,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IAE/C,gEAAgE;IAChE,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,wBAAwB,EAAE,SAAS,CAAC,CAAC;IACjE,IAAI,eAAe,EAAE;QACnB,QAAQ,GAAG,iBAAiB,CAAC,eAAe,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;KACjE;IAED,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC;AAC1C,CAAC"}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import cheerio from
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import { getDocusaurusLinksPerGroup } from
|
|
6
|
-
import
|
|
1
|
+
import cheerio from 'cheerio';
|
|
2
|
+
import combineNavWithEmptyGroupTitles from '../combineNavWithEmptyGroupTitles.js';
|
|
3
|
+
import downloadLogoImage from '../downloadLogoImage.js';
|
|
4
|
+
import { scrapeGettingFileNameFromUrl } from '../scrapeGettingFileNameFromUrl.js';
|
|
5
|
+
import { getDocusaurusLinksPerGroup } from './links-per-group/getDocusaurusLinksPerGroup.js';
|
|
6
|
+
import { scrapeDocusaurusPage } from './scrapeDocusaurusPage.js';
|
|
7
7
|
export async function scrapeDocusaurusSection(html, origin, cliDir, imageBaseDir, overwrite, version) {
|
|
8
8
|
const $ = cheerio.load(html);
|
|
9
9
|
// Download the logo
|
|
10
|
-
const logoSrc = $(
|
|
10
|
+
const logoSrc = $('.navbar__logo img').attr('src');
|
|
11
11
|
downloadLogoImage(logoSrc, imageBaseDir, origin, overwrite);
|
|
12
12
|
// Get all the navigation sections
|
|
13
|
-
const navigationSections = $(
|
|
13
|
+
const navigationSections = $('.theme-doc-sidebar-menu').first().children();
|
|
14
14
|
// Get all links per group
|
|
15
15
|
const groupsConfig = getDocusaurusLinksPerGroup(navigationSections, $, version);
|
|
16
16
|
// Merge groups with empty titles together
|
|
@@ -20,7 +20,7 @@ export async function scrapeDocusaurusSection(html, origin, cliDir, imageBaseDir
|
|
|
20
20
|
groupConfig.pages = (await Promise.all(groupConfig.pages.map(async (navEntry) =>
|
|
21
21
|
// Docusaurus requires a directory on all sections wheras we use root.
|
|
22
22
|
// /docs is their default directory so we remove it
|
|
23
|
-
scrapeGettingFileNameFromUrl(navEntry, cliDir, origin, overwrite, scrapeDocusaurusPage, false, version,
|
|
23
|
+
scrapeGettingFileNameFromUrl(navEntry, cliDir, origin, overwrite, scrapeDocusaurusPage, false, version, '/docs'))))
|
|
24
24
|
// Remove skipped index pages (they return undefined from the above function)
|
|
25
25
|
.filter(Boolean);
|
|
26
26
|
return groupConfig;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scrapeDocusaurusSection.js","sourceRoot":"","sources":["../../../src/scraping/site-scrapers/scrapeDocusaurusSection.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"scrapeDocusaurusSection.js","sourceRoot":"","sources":["../../../src/scraping/site-scrapers/scrapeDocusaurusSection.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAE9B,OAAO,8BAA8B,MAAM,sCAAsC,CAAC;AAClF,OAAO,iBAAiB,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,4BAA4B,EAAE,MAAM,oCAAoC,CAAC;AAClF,OAAO,EAAE,0BAA0B,EAAE,MAAM,iDAAiD,CAAC;AAC7F,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEjE,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,IAAY,EACZ,MAAc,EACd,MAAc,EACd,YAAoB,EACpB,SAAkB,EAClB,OAAgB;IAEhB,MAAM,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAE7B,oBAAoB;IACpB,MAAM,OAAO,GAAG,CAAC,CAAC,mBAAmB,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACnD,iBAAiB,CAAC,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;IAE5D,kCAAkC;IAClC,MAAM,kBAAkB,GAAG,CAAC,CAAC,yBAAyB,CAAC,CAAC,KAAK,EAAE,CAAC,QAAQ,EAAE,CAAC;IAE3E,0BAA0B;IAC1B,MAAM,YAAY,GAAqB,0BAA0B,CAAC,kBAAkB,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC;IAElG,0CAA0C;IAC1C,MAAM,mBAAmB,GAAG,8BAA8B,CAAC,YAAY,CAAC,CAAC;IAEzE,sCAAsC;IACtC,MAAM,sBAAsB,GAAG,MAAM,OAAO,CAAC,GAAG,CAC9C,mBAAmB,CAAC,GAAG,CAAC,KAAK,EAAE,WAAW,EAAE,EAAE;QAC5C,WAAW,CAAC,KAAK,GAAG,CAClB,MAAM,OAAO,CAAC,GAAG,CACf,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,QAA6B,EAAE,EAAE;QAC5D,sEAAsE;QACtE,mDAAmD;QACnD,4BAA4B,CAC1B,QAAQ,EACR,MAAM,EACN,MAAM,EACN,SAAS,EACT,oBAAoB,EACpB,KAAK,EACL,OAAO,EACP,OAAO,CACR,CACF,CACF,CACF;YACC,6EAA6E;aAC5E,MAAM,CAAC,OAAO,CAAC,CAAC;QACnB,OAAO,WAAW,CAAC;IACrB,CAAC,CAAC,CACH,CAAC;IAEF,OAAO,sBAAsB,CAAC;AAChC,CAAC"}
|
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
import cheerio from
|
|
2
|
-
import { NodeHtmlMarkdown } from
|
|
3
|
-
import downloadAllImages from
|
|
4
|
-
import replaceImagePaths from
|
|
1
|
+
import cheerio from 'cheerio';
|
|
2
|
+
import { NodeHtmlMarkdown } from 'node-html-markdown';
|
|
3
|
+
import downloadAllImages from '../downloadAllImages.js';
|
|
4
|
+
import replaceImagePaths from '../replaceImagePaths.js';
|
|
5
5
|
export async function scrapeGitBookPage(html, origin, cliDir, imageBaseDir, overwrite, _ // version
|
|
6
6
|
) {
|
|
7
7
|
const $ = cheerio.load(html);
|
|
8
8
|
const titleComponent = $('[data-testid="page.title"]').first();
|
|
9
9
|
const titleAndDescription = titleComponent.parent().parent().parent().text();
|
|
10
|
-
const description = titleAndDescription
|
|
11
|
-
.replace(titleComponent.text(), "")
|
|
12
|
-
.trim();
|
|
10
|
+
const description = titleAndDescription.replace(titleComponent.text(), '').trim();
|
|
13
11
|
const title = titleComponent.text().trim();
|
|
14
12
|
const content = $('[data-testid="page.contentEditor"]').first();
|
|
15
13
|
// Replace code blocks with parseable html
|
|
@@ -21,26 +19,26 @@ export async function scrapeGitBookPage(html, origin, cliDir, imageBaseDir, over
|
|
|
21
19
|
.children()
|
|
22
20
|
.toArray()
|
|
23
21
|
.map((d) => $(d).text())
|
|
24
|
-
.filter((text) => text !==
|
|
25
|
-
.join(
|
|
22
|
+
.filter((text) => text !== '')
|
|
23
|
+
.join('\n');
|
|
26
24
|
code.replaceWith(`<pre><code>${codeContent}</code></pre>`);
|
|
27
25
|
});
|
|
28
26
|
const contentHtml = $.html(content);
|
|
29
27
|
const modifyFileName = (fileName) =>
|
|
30
28
|
// Remove GitBook metadata from the start
|
|
31
29
|
// The first four %2F split metadata fields. Remaining ones are part of the file name.
|
|
32
|
-
fileName.split(
|
|
30
|
+
fileName.split('%2F').slice(4).join('%2F');
|
|
33
31
|
const origToWritePath = await downloadAllImages($, content, origin, imageBaseDir, overwrite, modifyFileName);
|
|
34
32
|
const nhm = new NodeHtmlMarkdown({ useInlineLinks: false });
|
|
35
33
|
let markdown = nhm.translate(contentHtml);
|
|
36
34
|
// Keep headers on one line
|
|
37
|
-
markdown = markdown.replace(/# \n\n/g,
|
|
35
|
+
markdown = markdown.replace(/# \n\n/g, '# ');
|
|
38
36
|
// Remove unnecessary nonwidth blank space characters
|
|
39
|
-
markdown = markdown.replace(/\u200b/g,
|
|
37
|
+
markdown = markdown.replace(/\u200b/g, '');
|
|
40
38
|
// Reduce unnecessary blank lines
|
|
41
|
-
markdown = markdown.replace(/\n\n\n/g,
|
|
39
|
+
markdown = markdown.replace(/\n\n\n/g, '\n\n');
|
|
42
40
|
// Mintlify doesn't support bolded headers, remove the asterisks
|
|
43
|
-
markdown = markdown.replace(/(\n#+) \*\*(.*)\*\*\n/g,
|
|
41
|
+
markdown = markdown.replace(/(\n#+) \*\*(.*)\*\*\n/g, '$1 $2\n');
|
|
44
42
|
if (origToWritePath) {
|
|
45
43
|
markdown = replaceImagePaths(origToWritePath, cliDir, markdown);
|
|
46
44
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scrapeGitBookPage.js","sourceRoot":"","sources":["../../../src/scraping/site-scrapers/scrapeGitBookPage.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"scrapeGitBookPage.js","sourceRoot":"","sources":["../../../src/scraping/site-scrapers/scrapeGitBookPage.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,OAAO,iBAAiB,MAAM,yBAAyB,CAAC;AACxD,OAAO,iBAAiB,MAAM,yBAAyB,CAAC;AAExD,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,IAAY,EACZ,MAAc,EACd,MAAc,EACd,YAAoB,EACpB,SAAkB,EAClB,CAAqB,CAAC,UAAU;;IAEhC,MAAM,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAE7B,MAAM,cAAc,GAAG,CAAC,CAAC,4BAA4B,CAAC,CAAC,KAAK,EAAE,CAAC;I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C,IAAI,CAAC,KAAK,CAAC,CAAC;IAE7C,MAAM,eAAe,GAAG,MAAM,iBAAiB,CAC7C,CAAC,EACD,OAAO,EACP,MAAM,EACN,YAAY,EACZ,SAAS,EACT,cAAc,CACf,CAAC;IAEF,MAAM,GAAG,GAAG,IAAI,gBAAgB,CAAC,EAAE,cAAc,EAAE,KAAK,EAAE,CAAC,CAAC;IAC5D,IAAI,QAAQ,GAAG,GAAG,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IAE1C,2BAA2B;IAC3B,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IAE7C,qDAAqD;IACrD,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;IAE3C,iCAAiC;IACjC,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IAE/C,gEAAgE;IAChE,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,wBAAwB,EAAE,SAAS,CAAC,CAAC;IACjE,IAAI,eAAe,EAAE;QACnB,QAAQ,GAAG,iBAAiB,CAAC,eAAe,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;KACjE;IAED,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC;AAC1C,CAAC"}
|
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
import cheerio from
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
1
|
+
import cheerio from 'cheerio';
|
|
2
|
+
import combineNavWithEmptyGroupTitles from '../combineNavWithEmptyGroupTitles.js';
|
|
3
|
+
import downloadLogoImage from '../downloadLogoImage.js';
|
|
4
|
+
import { scrapeGettingFileNameFromUrl } from '../scrapeGettingFileNameFromUrl.js';
|
|
5
|
+
import alternateGroupTitle from './alternateGroupTitle.js';
|
|
6
|
+
import getLinksRecursivelyGitBook from './links-per-group/getLinksRecursivelyGitBook.js';
|
|
7
|
+
import { scrapeGitBookPage } from './scrapeGitBookPage.js';
|
|
8
8
|
export async function scrapeGitBookSection(html, origin, cliDir, imageBaseDir, overwrite, version) {
|
|
9
9
|
const $ = cheerio.load(html);
|
|
10
10
|
// Download the logo
|
|
11
|
-
const logoSrc = $('a[data-testid="public.headerHomeLink"] img')
|
|
12
|
-
.first()
|
|
13
|
-
.attr("src");
|
|
11
|
+
const logoSrc = $('a[data-testid="public.headerHomeLink"] img').first().attr('src');
|
|
14
12
|
downloadLogoImage(logoSrc, imageBaseDir, origin, overwrite).catch(console.error);
|
|
15
13
|
// Get all the navigation sections
|
|
16
14
|
// Some variants of the GitBook UI show the logo and search base in the side navigation bar,
|
|
@@ -26,13 +24,10 @@ export async function scrapeGitBookSection(html, origin, cliDir, imageBaseDir, o
|
|
|
26
24
|
.toArray()
|
|
27
25
|
.map((s) => {
|
|
28
26
|
const section = $(s);
|
|
29
|
-
const sectionTitle = $(section)
|
|
30
|
-
.find('div > div[dir="auto"]')
|
|
31
|
-
.first()
|
|
32
|
-
.text();
|
|
27
|
+
const sectionTitle = $(section).find('div > div[dir="auto"]').first().text();
|
|
33
28
|
// Only present if the nested navigation is not in a group
|
|
34
29
|
const firstLink = section.children().eq(0);
|
|
35
|
-
const firstHref = firstLink.attr(
|
|
30
|
+
const firstHref = firstLink.attr('href');
|
|
36
31
|
const linkSections = section.children().eq(1).children();
|
|
37
32
|
const pages = getLinksRecursivelyGitBook(linkSections, $);
|
|
38
33
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scrapeGitBookSection.js","sourceRoot":"","sources":["../../../src/scraping/site-scrapers/scrapeGitBookSection.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"scrapeGitBookSection.js","sourceRoot":"","sources":["../../../src/scraping/site-scrapers/scrapeGitBookSection.ts"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E,CAAC;QAE7E,0DAA0D;QAC1D,MAAM,SAAS,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QAC3C,MAAM,SAAS,GAAG,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAEzC,MAAM,YAAY,GAAoB,OAAO,CAAC,QAAQ,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;QAC1E,MAAM,KAAK,GAAG,0BAA0B,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC;QAE1D,OAAO;YACL,KAAK,EAAE,YAAY,IAAI,mBAAmB,CAAC,SAAS,EAAE,KAAK,CAAC;YAC5D,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK;SACjD,CAAC;IACJ,CAAC,CAAC;SACD,MAAM,CAAC,OAAO,CAAC,CAAC;IAEnB,0CAA0C;IAC1C,MAAM,mBAAmB,GAAG,8BAA8B,CAAC,YAAY,CAAC,CAAC;IAEzE,sCAAsC;IACtC,OAAO,OAAO,CAAC,GAAG,CAChB,mBAAmB,CAAC,GAAG,CAAC,KAAK,EAAE,QAA6B,EAAE,EAAE;QAC9D,OAAO,MAAM,4BAA4B,CACvC,QAAQ,EACR,MAAM,EACN,MAAM,EACN,SAAS,EACT,iBAAiB,EACjB,IAAI,EACJ,OAAO,CACR,CAAC;IACJ,CAAC,CAAC,CACH,CAAC;AACJ,CAAC"}
|
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
import cheerio from
|
|
2
|
-
import { NodeHtmlMarkdown } from
|
|
3
|
-
import downloadAllImages from
|
|
4
|
-
import replaceImagePaths from
|
|
1
|
+
import cheerio from 'cheerio';
|
|
2
|
+
import { NodeHtmlMarkdown } from 'node-html-markdown';
|
|
3
|
+
import downloadAllImages from '../downloadAllImages.js';
|
|
4
|
+
import replaceImagePaths from '../replaceImagePaths.js';
|
|
5
5
|
export async function scrapeReadMePage(html, origin, cliDir, imageBaseDir, overwrite, _ // version
|
|
6
6
|
) {
|
|
7
7
|
const $ = cheerio.load(html);
|
|
8
|
-
const titleComponent = $(
|
|
8
|
+
const titleComponent = $('h1').first();
|
|
9
9
|
const title = titleComponent.text().trim();
|
|
10
|
-
let description = $(
|
|
10
|
+
let description = $('.markdown-body', titleComponent.parent()).text().trim();
|
|
11
11
|
if (!description) {
|
|
12
|
-
description = $(
|
|
12
|
+
description = $('.rm-Article > header p').text().trim();
|
|
13
13
|
}
|
|
14
|
-
let content = $(
|
|
14
|
+
let content = $('.content-body .markdown-body').first();
|
|
15
15
|
if (content.length === 0) {
|
|
16
|
-
content = $(
|
|
16
|
+
content = $('.rm-Article > .markdown-body');
|
|
17
17
|
}
|
|
18
18
|
// API Pages don't have a markdown body in the same position so there's no HTML
|
|
19
|
-
const contentHtml = content.html() ||
|
|
19
|
+
const contentHtml = content.html() || '';
|
|
20
20
|
const origToWritePath = await downloadAllImages($, content, origin, imageBaseDir, overwrite);
|
|
21
21
|
const nhm = new NodeHtmlMarkdown({ useInlineLinks: false });
|
|
22
22
|
let markdown = nhm.translate(contentHtml);
|
|
23
23
|
// Keep headers on one line and increase their depth by one
|
|
24
|
-
markdown = markdown.replace(/# \n\n/g,
|
|
24
|
+
markdown = markdown.replace(/# \n\n/g, '## ');
|
|
25
25
|
// Remove unnecessary nonwidth blank space characters
|
|
26
|
-
markdown = markdown.replace(/\u200b/g,
|
|
26
|
+
markdown = markdown.replace(/\u200b/g, '');
|
|
27
27
|
// Remove ReadMe anchor links
|
|
28
|
-
markdown = markdown.replace(/\n\[\]\(#.+\)\n/g,
|
|
28
|
+
markdown = markdown.replace(/\n\[\]\(#.+\)\n/g, '\n');
|
|
29
29
|
// Reduce unnecessary blank lines
|
|
30
|
-
markdown = markdown.replace(/\n\n\n/g,
|
|
30
|
+
markdown = markdown.replace(/\n\n\n/g, '\n\n');
|
|
31
31
|
// Mintlify doesn't support bolded headers, remove the asterisks
|
|
32
|
-
markdown = markdown.replace(/(\n#+) \*\*(.*)\*\*\n/g,
|
|
32
|
+
markdown = markdown.replace(/(\n#+) \*\*(.*)\*\*\n/g, '$1 $2\n');
|
|
33
33
|
if (origToWritePath) {
|
|
34
34
|
markdown = replaceImagePaths(origToWritePath, cliDir, markdown);
|
|
35
35
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scrapeReadMePage.js","sourceRoot":"","sources":["../../../src/scraping/site-scrapers/scrapeReadMePage.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"scrapeReadMePage.js","sourceRoot":"","sources":["../../../src/scraping/site-scrapers/scrapeReadMePage.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,OAAO,iBAAiB,MAAM,yBAAyB,CAAC;AACxD,OAAO,iBAAiB,MAAM,yBAAyB,CAAC;AAExD,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,IAAY,EACZ,MAAc,EACd,MAAc,EACd,YAAoB,EACpB,SAAkB,EAClB,CAAqB,CAAC,UAAU;;IAEhC,MAAM,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAE7B,MAAM,cAAc,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,CAAC;IACvC,MAAM,KAAK,GAAG,cAAc,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC;IAC3C,IAAI,WAAW,GAAG,CAAC,CAAC,gBAAgB,EAAE,cAAc,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC;IAC7E,IAAI,CAAC,WAAW,EAAE;QAChB,WAAW,GAAG,C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C,CAAC"}
|
|
@@ -1,30 +1,26 @@
|
|
|
1
|
-
import cheerio from
|
|
2
|
-
import
|
|
3
|
-
import { scrapeGettingFileNameFromUrl } from
|
|
4
|
-
import getLinksRecursively from
|
|
5
|
-
import
|
|
1
|
+
import cheerio from 'cheerio';
|
|
2
|
+
import downloadLogoImage from '../downloadLogoImage.js';
|
|
3
|
+
import { scrapeGettingFileNameFromUrl } from '../scrapeGettingFileNameFromUrl.js';
|
|
4
|
+
import getLinksRecursively from './links-per-group/getLinksRecursively.js';
|
|
5
|
+
import { scrapeReadMePage } from './scrapeReadMePage.js';
|
|
6
6
|
export async function scrapeReadMeSection(html, origin, cliDir, imageBaseDir, overwrite, version) {
|
|
7
7
|
const $ = cheerio.load(html);
|
|
8
8
|
// Download the logo
|
|
9
|
-
const logoSrc = $(
|
|
9
|
+
const logoSrc = $('.rm-Logo-img').first().attr('src');
|
|
10
10
|
downloadLogoImage(logoSrc, imageBaseDir, origin, overwrite).catch(console.error);
|
|
11
11
|
// Get all the navigation sections, but only from the first
|
|
12
12
|
// sidebar found. There are multiple in the HTML for mobile
|
|
13
13
|
// responsiveness but they all have the same links.
|
|
14
|
-
const navigationSections = $(
|
|
15
|
-
|
|
16
|
-
.find(".rm-Sidebar-section");
|
|
17
|
-
const groupsConfig = navigationSections
|
|
18
|
-
.toArray()
|
|
19
|
-
.map((s) => {
|
|
14
|
+
const navigationSections = $('.rm-Sidebar').first().find('.rm-Sidebar-section');
|
|
15
|
+
const groupsConfig = navigationSections.toArray().map((s) => {
|
|
20
16
|
const section = $(s);
|
|
21
|
-
const sectionTitle = section.find(
|
|
17
|
+
const sectionTitle = section.find('h3').first().text();
|
|
22
18
|
// Get all links, then use filter to remove duplicates.
|
|
23
19
|
// There are duplicates because of nested navigation, eg:
|
|
24
20
|
// subgroupTitle -> /first-page
|
|
25
21
|
// -- First Page -> /first-page ** DUPLICATE **
|
|
26
22
|
// -- Second Page -> /second-page
|
|
27
|
-
const linkSections = section.find(
|
|
23
|
+
const linkSections = section.find('.rm-Sidebar-list').first().children();
|
|
28
24
|
const pages = getLinksRecursively(linkSections, $).filter((value, index, self) => self.indexOf(value) === index);
|
|
29
25
|
// Follows the same structure as mint.json
|
|
30
26
|
return {
|
|
@@ -37,7 +33,7 @@ export async function scrapeReadMeSection(html, origin, cliDir, imageBaseDir, ov
|
|
|
37
33
|
return await scrapeGettingFileNameFromUrl(
|
|
38
34
|
// ReadMe requires a directory on all sections whereas we use root.
|
|
39
35
|
// /docs is their default directory so we remove it
|
|
40
|
-
navEntry, cliDir, origin, overwrite, scrapeReadMePage, false, version,
|
|
36
|
+
navEntry, cliDir, origin, overwrite, scrapeReadMePage, false, version, '/docs');
|
|
41
37
|
}));
|
|
42
38
|
}
|
|
43
39
|
//# sourceMappingURL=scrapeReadMeSection.js.map
|