mintlify 1.0.5 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/index.js +18 -8
- package/bin/index.js.map +1 -1
- package/bin/scrapeGitBookPage.js +28 -0
- package/bin/scrapeGitBookPage.js.map +1 -0
- package/bin/scrapeReadMe.js +54 -22
- package/bin/scrapeReadMe.js.map +1 -1
- package/bin/scrapeReadMePage.js +28 -0
- package/bin/scrapeReadMePage.js.map +1 -0
- package/bin/util.js +25 -3
- package/bin/util.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +19 -8
- package/src/{scrapeGitBook.ts → scrapeGitBookPage.ts} +1 -1
- package/src/scrapeReadMe.ts +64 -22
- package/src/scrapeReadMePage.ts +37 -0
- package/src/util.ts +30 -6
package/bin/index.js
CHANGED
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
import { writeFileSync } from "fs";
|
|
3
3
|
import inquirer from "inquirer";
|
|
4
4
|
import { MintConfig } from "./templates.js";
|
|
5
|
-
import { createPage, toFilename } from "./util.js";
|
|
6
|
-
import {
|
|
5
|
+
import { createPage, toFilename, objToReadableString } from "./util.js";
|
|
6
|
+
import { scrapeGitBookPage } from "./scrapeGitBookPage.js";
|
|
7
|
+
import { scrapeReadMePage } from "./scrapeReadMePage.js";
|
|
7
8
|
import { scrapeReadMe } from "./scrapeReadMe.js";
|
|
8
9
|
const args = process.argv.slice(2);
|
|
9
10
|
if (args.length === 0) {
|
|
@@ -82,16 +83,25 @@ if (command === "page") {
|
|
|
82
83
|
process.exit(1);
|
|
83
84
|
});
|
|
84
85
|
}
|
|
85
|
-
if (command === "scrape-gitbook") {
|
|
86
|
+
if (command === "scrape-gitbook-page") {
|
|
86
87
|
const url = args[1];
|
|
87
|
-
const { title, description, markdown } = await
|
|
88
|
-
createPage(title, description, markdown, process.
|
|
88
|
+
const { title, description, markdown } = await scrapeGitBookPage(url);
|
|
89
|
+
createPage(title, description, markdown, process.cwd());
|
|
89
90
|
process.exit(1);
|
|
90
91
|
}
|
|
91
|
-
if (command === "scrape-readme") {
|
|
92
|
+
if (command === "scrape-readme-page") {
|
|
92
93
|
const url = args[1];
|
|
93
|
-
const { title, description, markdown } = await
|
|
94
|
-
createPage(title, description, markdown, process.
|
|
94
|
+
const { title, description, markdown } = await scrapeReadMePage(url);
|
|
95
|
+
createPage(title, description, markdown, process.cwd());
|
|
96
|
+
process.exit(1);
|
|
97
|
+
}
|
|
98
|
+
if (command === "scrape-readme-section") {
|
|
99
|
+
const url = args[1];
|
|
100
|
+
console.log("Started scraping...");
|
|
101
|
+
const groupsConfig = await scrapeReadMe(url, process.cwd());
|
|
102
|
+
console.log("Finished scraping.");
|
|
103
|
+
console.log("Add the following to your navigation in mint.config.js:");
|
|
104
|
+
console.log(objToReadableString(groupsConfig));
|
|
95
105
|
process.exit(1);
|
|
96
106
|
}
|
|
97
107
|
//# sourceMappingURL=index.js.map
|
package/bin/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AACnC,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AACnC,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AACxE,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC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,EAAE,GAAG,MAAM,iBAAiB,CAAC,GAAG,CAAC,CAAC;IACtE,UAAU,CAAC,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IACxD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;CACjB;AAED,IAAI,OAAO,KAAK,oBAAoB,EAAE;IACpC,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,GAAG,MAAM,gBAAgB,CAAC,GAAG,CAAC,CAAC;IACrE,UAAU,CAAC,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IACxD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;CACjB;AAED,IAAI,OAAO,KAAK,uBAAuB,EAAE;IACvC,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC;IACnC,MAAM,YAAY,GAAG,MAAM,YAAY,CAAC,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IAC5D,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC;IAClC,OAAO,CAAC,GAAG,CAAC,yDAAyD,CAAC,CAAC;IACvE,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,YAAY,CAAC,CAAC,CAAC;IAC/C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;CACjB"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import cheerio from "cheerio";
|
|
3
|
+
import { NodeHtmlMarkdown } from "node-html-markdown";
|
|
4
|
+
export async function scrapeGitBookPage(url) {
|
|
5
|
+
const res = await axios.default.get(url);
|
|
6
|
+
const $ = cheerio.load(res.data);
|
|
7
|
+
const titleComponent = $('[data-testid="page.title"]').first();
|
|
8
|
+
const titleAndDescription = titleComponent.parent().parent().parent().text();
|
|
9
|
+
console.log(titleAndDescription);
|
|
10
|
+
const description = titleAndDescription
|
|
11
|
+
.replace(titleComponent.text(), "")
|
|
12
|
+
.trim();
|
|
13
|
+
const title = titleComponent.text().trim();
|
|
14
|
+
const content = $('[data-testid="page.contentEditor"]').first();
|
|
15
|
+
const contentHtml = $.html(content);
|
|
16
|
+
const nhm = new NodeHtmlMarkdown();
|
|
17
|
+
let markdown = nhm.translate(contentHtml);
|
|
18
|
+
// Keep headers on one line and increase their depth by one
|
|
19
|
+
markdown = markdown.replace(/# \n\n/g, "## ");
|
|
20
|
+
// Remove unnecessary nonwidth blank space characters
|
|
21
|
+
markdown = markdown.replace(/\u200b/g, "");
|
|
22
|
+
// Reduce unnecessary blank lines
|
|
23
|
+
markdown = markdown.replace(/\n\n\n/g, "\n\n");
|
|
24
|
+
// Mintlify doesn't support bolded headers, remove the asterisks
|
|
25
|
+
markdown = markdown.replace(/(\n#+) \*\*(.*)\*\*\n/g, "$1 $2\n");
|
|
26
|
+
return { title, description, markdown };
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=scrapeGitBookPage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scrapeGitBookPage.js","sourceRoot":"","sources":["../src/scrapeGitBookPage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,GAAW;IACjD,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACzC,MAAM,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAEjC,MAAM,cAAc,GA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4
|
-
|
|
3
|
+
import path from "path";
|
|
4
|
+
import { scrapeReadMePage } from "./scrapeReadMePage.js";
|
|
5
|
+
import { createPage, getWebsite } from "./util.js";
|
|
6
|
+
export async function scrapeReadMe(url, cliDir) {
|
|
5
7
|
const res = await axios.default.get(url);
|
|
6
8
|
const $ = cheerio.load(res.data);
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
.
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
9
|
+
const website = getWebsite(url);
|
|
10
|
+
// Get all the navigation sections
|
|
11
|
+
const navigationSections = $(".rm-Sidebar-section");
|
|
12
|
+
const groupsConfig = navigationSections
|
|
13
|
+
.map((i, section) => {
|
|
14
|
+
const sectionTitle = $(section).find("h3").first().text();
|
|
15
|
+
const linkPaths = $(section)
|
|
16
|
+
.find("a[href]")
|
|
17
|
+
.map((i, link) => {
|
|
18
|
+
const href = $(link).attr("href");
|
|
19
|
+
// Skip external links until Mintlify supports them
|
|
20
|
+
if (href.startsWith("https://") || href.startsWith("http://")) {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
return href;
|
|
24
|
+
})
|
|
25
|
+
.toArray();
|
|
26
|
+
// Follows the same structure as mint.config.js
|
|
27
|
+
return {
|
|
28
|
+
group: sectionTitle,
|
|
29
|
+
pages: linkPaths,
|
|
30
|
+
};
|
|
31
|
+
})
|
|
32
|
+
.toArray();
|
|
33
|
+
return await Promise.all(groupsConfig.map(async (groupConfig) => {
|
|
34
|
+
groupConfig.pages = await Promise.all(groupConfig.pages.map(async (page) => {
|
|
35
|
+
// Scrape each page separately
|
|
36
|
+
const { title, description, markdown } = await scrapeReadMePage(website + page);
|
|
37
|
+
// Removes file name from the end
|
|
38
|
+
const splitSubpath = page.split("/");
|
|
39
|
+
let folders = splitSubpath
|
|
40
|
+
.slice(0, splitSubpath.length - 1)
|
|
41
|
+
.join("/");
|
|
42
|
+
// ReadMe requires a directory on all sections wheras we use root.
|
|
43
|
+
// docs/ is their home directory so we remove it
|
|
44
|
+
if (folders.startsWith("/docs")) {
|
|
45
|
+
folders = folders.replace("/docs", "");
|
|
46
|
+
}
|
|
47
|
+
const newFileLocation = folders ? path.join(cliDir, folders) : cliDir;
|
|
48
|
+
// Default to introduction.mdx if we encountered index.html
|
|
49
|
+
const fileName = splitSubpath.length === 2
|
|
50
|
+
? "introduction"
|
|
51
|
+
: splitSubpath[splitSubpath.length - 1];
|
|
52
|
+
// Will create subfolders as needed
|
|
53
|
+
createPage(title, description, markdown, newFileLocation, fileName);
|
|
54
|
+
// Removes first slash if we are in a folder, Mintlify doesn't need it
|
|
55
|
+
return folders ? path.join(folders, fileName).substring(1) : fileName;
|
|
56
|
+
}));
|
|
57
|
+
return groupConfig;
|
|
58
|
+
}));
|
|
27
59
|
}
|
|
28
60
|
//# sourceMappingURL=scrapeReadMe.js.map
|
package/bin/scrapeReadMe.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scrapeReadMe.js","sourceRoot":"","sources":["../src/scrapeReadMe.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,gBAAgB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"scrapeReadMe.js","sourceRoot":"","sources":["../src/scrapeReadMe.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,UAAU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O,WAAW,CAAC;IACrB,CAAC,CAAC,CACH,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import cheerio from "cheerio";
|
|
3
|
+
import { NodeHtmlMarkdown } from "node-html-markdown";
|
|
4
|
+
export async function scrapeReadMePage(url) {
|
|
5
|
+
const res = await axios.default.get(url);
|
|
6
|
+
const $ = cheerio.load(res.data);
|
|
7
|
+
const titleComponent = $("h1").first();
|
|
8
|
+
const title = titleComponent.text().trim();
|
|
9
|
+
const description = $(".markdown-body", titleComponent.parent())
|
|
10
|
+
.text()
|
|
11
|
+
.trim();
|
|
12
|
+
const content = $(".content-body .markdown-body").first();
|
|
13
|
+
const contentHtml = $.html(content);
|
|
14
|
+
const nhm = new NodeHtmlMarkdown();
|
|
15
|
+
let markdown = nhm.translate(contentHtml);
|
|
16
|
+
// Keep headers on one line and increase their depth by one
|
|
17
|
+
markdown = markdown.replace(/# \n\n/g, "## ");
|
|
18
|
+
// Remove unnecessary nonwidth blank space characters
|
|
19
|
+
markdown = markdown.replace(/\u200b/g, "");
|
|
20
|
+
// Remove ReadMe anchor links
|
|
21
|
+
markdown = markdown.replace(/\n\[\]\(#.+\)\n/g, "\n");
|
|
22
|
+
// Reduce unnecessary blank lines
|
|
23
|
+
markdown = markdown.replace(/\n\n\n/g, "\n\n");
|
|
24
|
+
// Mintlify doesn't support bolded headers, remove the asterisks
|
|
25
|
+
markdown = markdown.replace(/(\n#+) \*\*(.*)\*\*\n/g, "$1 $2\n");
|
|
26
|
+
return { title, description, markdown };
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=scrapeReadMePage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scrapeReadMePage.js","sourceRoot":"","sources":["../src/scrapeReadMePage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,O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AAS,CAAC,CAAC;IAEjE,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC;AAC1C,CAAC"}
|
package/bin/util.js
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
|
-
import { writeFileSync } from "fs";
|
|
1
|
+
import { mkdirSync, writeFileSync } from "fs";
|
|
2
2
|
import { Page } from "./templates.js";
|
|
3
|
+
import path from "path";
|
|
4
|
+
export function getWebsite(url) {
|
|
5
|
+
// Gets the website
|
|
6
|
+
// eg. https://google.com -> https://google.com
|
|
7
|
+
// https://google.com/page -> https://google.com
|
|
8
|
+
return url.split("/").slice(0, 3).join("/");
|
|
9
|
+
}
|
|
10
|
+
export function objToReadableString(objs) {
|
|
11
|
+
// Two spaces as indentation
|
|
12
|
+
return objs.map((obj) => JSON.stringify(obj, null, 2)).join(",\n");
|
|
13
|
+
}
|
|
3
14
|
export const toFilename = (title) => {
|
|
4
15
|
// Gets rid of special characters at the start and end
|
|
5
16
|
// of the name by converting to spaces then using trim.
|
|
@@ -9,7 +20,18 @@ export const toFilename = (title) => {
|
|
|
9
20
|
.replace(/ /g, "-")
|
|
10
21
|
.toLowerCase();
|
|
11
22
|
};
|
|
12
|
-
export const
|
|
13
|
-
|
|
23
|
+
export const addMdx = (fileName) => {
|
|
24
|
+
if (fileName.endsWith(".mdx")) {
|
|
25
|
+
return fileName;
|
|
26
|
+
}
|
|
27
|
+
return fileName + ".mdx";
|
|
28
|
+
};
|
|
29
|
+
export const createPage = (title, description, markdown, rootDir = "", fileName) => {
|
|
30
|
+
// Create the folders needed if they're missing
|
|
31
|
+
mkdirSync(rootDir, { recursive: true });
|
|
32
|
+
// Write the page to memory
|
|
33
|
+
const writePath = path.join(rootDir, addMdx(fileName || toFilename(title)));
|
|
34
|
+
writeFileSync(writePath, Page(title, description, markdown));
|
|
35
|
+
console.log("✏️ - " + writePath);
|
|
14
36
|
};
|
|
15
37
|
//# sourceMappingURL=util.js.map
|
package/bin/util.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AAC9C,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACtC,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,MAAM,UAAU,UAAU,CAAC,GAAW;IACpC,mBAAmB;IACnB,+CAA+C;IAC/C,gDAAgD;IAChD,OAAO,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC9C,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,IAAc;IAChD,4BAA4B;IAC5B,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AACrE,CAAC;AAED,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,KAAa,EAAE,EAAE;IAC1C,sDAAsD;IACtD,uDAAuD;IACvD,OAAO,KAAK;SACT,OAAO,CAAC,aAAa,EAAE,GAAG,CAAC;SAC3B,IAAI,EAAE;SACN,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC;SAClB,WAAW,EAAE,CAAC;AACnB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,QAAgB,EAAE,EAAE;IACzC,IAAI,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;QAC7B,OAAO,QAAQ,CAAC;KACjB;IACD,OAAO,QAAQ,GAAG,MAAM,CAAC;AAC3B,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAAG,CACxB,KAAa,EACb,WAAoB,EACpB,QAAiB,EACjB,UAAkB,EAAE,EACpB,QAAiB,EACjB,EAAE;IACF,+CAA+C;IAC/C,SAAS,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAExC,2BAA2B;IAC3B,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,QAAQ,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAC5E,aAAa,CAAC,SAAS,EAAE,IAAI,CAAC,KAAK,EAAE,WAAW,EAAE,QAAQ,CAAC,CAAC,CAAC;IAC7D,OAAO,CAAC,GAAG,CAAC,OAAO,GAAG,SAAS,CAAC,CAAC;AACnC,CAAC,CAAC"}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
import { writeFileSync } from "fs";
|
|
4
4
|
import inquirer from "inquirer";
|
|
5
5
|
import { MintConfig } from "./templates.js";
|
|
6
|
-
import { createPage, toFilename } from "./util.js";
|
|
7
|
-
import {
|
|
6
|
+
import { createPage, toFilename, objToReadableString } from "./util.js";
|
|
7
|
+
import { scrapeGitBookPage } from "./scrapeGitBookPage.js";
|
|
8
|
+
import { scrapeReadMePage } from "./scrapeReadMePage.js";
|
|
8
9
|
import { scrapeReadMe } from "./scrapeReadMe.js";
|
|
9
10
|
|
|
10
11
|
const args = process.argv.slice(2);
|
|
@@ -99,16 +100,26 @@ if (command === "page") {
|
|
|
99
100
|
});
|
|
100
101
|
}
|
|
101
102
|
|
|
102
|
-
if (command === "scrape-gitbook") {
|
|
103
|
+
if (command === "scrape-gitbook-page") {
|
|
103
104
|
const url = args[1];
|
|
104
|
-
const { title, description, markdown } = await
|
|
105
|
-
createPage(title, description, markdown, process.
|
|
105
|
+
const { title, description, markdown } = await scrapeGitBookPage(url);
|
|
106
|
+
createPage(title, description, markdown, process.cwd());
|
|
106
107
|
process.exit(1);
|
|
107
108
|
}
|
|
108
109
|
|
|
109
|
-
if (command === "scrape-readme") {
|
|
110
|
+
if (command === "scrape-readme-page") {
|
|
110
111
|
const url = args[1];
|
|
111
|
-
const { title, description, markdown } = await
|
|
112
|
-
createPage(title, description, markdown, process.
|
|
112
|
+
const { title, description, markdown } = await scrapeReadMePage(url);
|
|
113
|
+
createPage(title, description, markdown, process.cwd());
|
|
114
|
+
process.exit(1);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (command === "scrape-readme-section") {
|
|
118
|
+
const url = args[1];
|
|
119
|
+
console.log("Started scraping...");
|
|
120
|
+
const groupsConfig = await scrapeReadMe(url, process.cwd());
|
|
121
|
+
console.log("Finished scraping.");
|
|
122
|
+
console.log("Add the following to your navigation in mint.config.js:");
|
|
123
|
+
console.log(objToReadableString(groupsConfig));
|
|
113
124
|
process.exit(1);
|
|
114
125
|
}
|
|
@@ -2,7 +2,7 @@ import axios from "axios";
|
|
|
2
2
|
import cheerio from "cheerio";
|
|
3
3
|
import { NodeHtmlMarkdown } from "node-html-markdown";
|
|
4
4
|
|
|
5
|
-
export async function
|
|
5
|
+
export async function scrapeGitBookPage(url: string) {
|
|
6
6
|
const res = await axios.default.get(url);
|
|
7
7
|
const $ = cheerio.load(res.data);
|
|
8
8
|
|
package/src/scrapeReadMe.ts
CHANGED
|
@@ -1,37 +1,79 @@
|
|
|
1
1
|
import axios from "axios";
|
|
2
2
|
import cheerio from "cheerio";
|
|
3
|
-
import
|
|
3
|
+
import path from "path";
|
|
4
|
+
import { scrapeReadMePage } from "./scrapeReadMePage.js";
|
|
5
|
+
import { createPage, getWebsite, addMdx } from "./util.js";
|
|
4
6
|
|
|
5
|
-
export async function scrapeReadMe(url: string) {
|
|
7
|
+
export async function scrapeReadMe(url: string, cliDir: string) {
|
|
6
8
|
const res = await axios.default.get(url);
|
|
7
9
|
const $ = cheerio.load(res.data);
|
|
10
|
+
const website = getWebsite(url);
|
|
8
11
|
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
const description = $(".markdown-body", titleComponent.parent())
|
|
12
|
-
.text()
|
|
13
|
-
.trim();
|
|
12
|
+
// Get all the navigation sections
|
|
13
|
+
const navigationSections = $(".rm-Sidebar-section");
|
|
14
14
|
|
|
15
|
-
const
|
|
16
|
-
|
|
15
|
+
const groupsConfig = navigationSections
|
|
16
|
+
.map((i, section) => {
|
|
17
|
+
const sectionTitle = $(section).find("h3").first().text();
|
|
18
|
+
const linkPaths = $(section)
|
|
19
|
+
.find("a[href]")
|
|
20
|
+
.map((i, link) => {
|
|
21
|
+
const href = $(link).attr("href");
|
|
17
22
|
|
|
18
|
-
|
|
19
|
-
|
|
23
|
+
// Skip external links until Mintlify supports them
|
|
24
|
+
if (href.startsWith("https://") || href.startsWith("http://")) {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
20
27
|
|
|
21
|
-
|
|
22
|
-
|
|
28
|
+
return href;
|
|
29
|
+
})
|
|
30
|
+
.toArray();
|
|
23
31
|
|
|
24
|
-
|
|
25
|
-
|
|
32
|
+
// Follows the same structure as mint.config.js
|
|
33
|
+
return {
|
|
34
|
+
group: sectionTitle,
|
|
35
|
+
pages: linkPaths,
|
|
36
|
+
};
|
|
37
|
+
})
|
|
38
|
+
.toArray();
|
|
26
39
|
|
|
27
|
-
|
|
28
|
-
|
|
40
|
+
return await Promise.all(
|
|
41
|
+
groupsConfig.map(async (groupConfig) => {
|
|
42
|
+
groupConfig.pages = await Promise.all(
|
|
43
|
+
groupConfig.pages.map(async (page: string) => {
|
|
44
|
+
// Scrape each page separately
|
|
45
|
+
const { title, description, markdown } = await scrapeReadMePage(
|
|
46
|
+
website + page
|
|
47
|
+
);
|
|
29
48
|
|
|
30
|
-
|
|
31
|
-
|
|
49
|
+
// Removes file name from the end
|
|
50
|
+
const splitSubpath = page.split("/");
|
|
51
|
+
let folders = splitSubpath
|
|
52
|
+
.slice(0, splitSubpath.length - 1)
|
|
53
|
+
.join("/");
|
|
32
54
|
|
|
33
|
-
|
|
34
|
-
|
|
55
|
+
// ReadMe requires a directory on all sections wheras we use root.
|
|
56
|
+
// docs/ is their home directory so we remove it
|
|
57
|
+
if (folders.startsWith("/docs")) {
|
|
58
|
+
folders = folders.replace("/docs", "");
|
|
59
|
+
}
|
|
35
60
|
|
|
36
|
-
|
|
61
|
+
const newFileLocation = folders ? path.join(cliDir, folders) : cliDir;
|
|
62
|
+
|
|
63
|
+
// Default to introduction.mdx if we encountered index.html
|
|
64
|
+
const fileName =
|
|
65
|
+
splitSubpath.length === 2
|
|
66
|
+
? "introduction"
|
|
67
|
+
: splitSubpath[splitSubpath.length - 1];
|
|
68
|
+
|
|
69
|
+
// Will create subfolders as needed
|
|
70
|
+
createPage(title, description, markdown, newFileLocation, fileName);
|
|
71
|
+
|
|
72
|
+
// Removes first slash if we are in a folder, Mintlify doesn't need it
|
|
73
|
+
return folders ? path.join(folders, fileName).substring(1) : fileName;
|
|
74
|
+
})
|
|
75
|
+
);
|
|
76
|
+
return groupConfig;
|
|
77
|
+
})
|
|
78
|
+
);
|
|
37
79
|
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import cheerio from "cheerio";
|
|
3
|
+
import { NodeHtmlMarkdown } from "node-html-markdown";
|
|
4
|
+
|
|
5
|
+
export async function scrapeReadMePage(url: string) {
|
|
6
|
+
const res = await axios.default.get(url);
|
|
7
|
+
const $ = cheerio.load(res.data);
|
|
8
|
+
|
|
9
|
+
const titleComponent = $("h1").first();
|
|
10
|
+
const title = titleComponent.text().trim();
|
|
11
|
+
const description = $(".markdown-body", titleComponent.parent())
|
|
12
|
+
.text()
|
|
13
|
+
.trim();
|
|
14
|
+
|
|
15
|
+
const content = $(".content-body .markdown-body").first();
|
|
16
|
+
const contentHtml = $.html(content);
|
|
17
|
+
|
|
18
|
+
const nhm = new NodeHtmlMarkdown();
|
|
19
|
+
let markdown = nhm.translate(contentHtml);
|
|
20
|
+
|
|
21
|
+
// Keep headers on one line and increase their depth by one
|
|
22
|
+
markdown = markdown.replace(/# \n\n/g, "## ");
|
|
23
|
+
|
|
24
|
+
// Remove unnecessary nonwidth blank space characters
|
|
25
|
+
markdown = markdown.replace(/\u200b/g, "");
|
|
26
|
+
|
|
27
|
+
// Remove ReadMe anchor links
|
|
28
|
+
markdown = markdown.replace(/\n\[\]\(#.+\)\n/g, "\n");
|
|
29
|
+
|
|
30
|
+
// Reduce unnecessary blank lines
|
|
31
|
+
markdown = markdown.replace(/\n\n\n/g, "\n\n");
|
|
32
|
+
|
|
33
|
+
// Mintlify doesn't support bolded headers, remove the asterisks
|
|
34
|
+
markdown = markdown.replace(/(\n#+) \*\*(.*)\*\*\n/g, "$1 $2\n");
|
|
35
|
+
|
|
36
|
+
return { title, description, markdown };
|
|
37
|
+
}
|
package/src/util.ts
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
|
-
import { writeFileSync } from "fs";
|
|
1
|
+
import { mkdirSync, writeFileSync } from "fs";
|
|
2
2
|
import { Page } from "./templates.js";
|
|
3
|
+
import path from "path";
|
|
4
|
+
|
|
5
|
+
export function getWebsite(url: string) {
|
|
6
|
+
// Gets the website
|
|
7
|
+
// eg. https://google.com -> https://google.com
|
|
8
|
+
// https://google.com/page -> https://google.com
|
|
9
|
+
return url.split("/").slice(0, 3).join("/");
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function objToReadableString(objs: Object[]) {
|
|
13
|
+
// Two spaces as indentation
|
|
14
|
+
return objs.map((obj) => JSON.stringify(obj, null, 2)).join(",\n");
|
|
15
|
+
}
|
|
3
16
|
|
|
4
17
|
export const toFilename = (title: string) => {
|
|
5
18
|
// Gets rid of special characters at the start and end
|
|
@@ -11,14 +24,25 @@ export const toFilename = (title: string) => {
|
|
|
11
24
|
.toLowerCase();
|
|
12
25
|
};
|
|
13
26
|
|
|
27
|
+
export const addMdx = (fileName: string) => {
|
|
28
|
+
if (fileName.endsWith(".mdx")) {
|
|
29
|
+
return fileName;
|
|
30
|
+
}
|
|
31
|
+
return fileName + ".mdx";
|
|
32
|
+
};
|
|
33
|
+
|
|
14
34
|
export const createPage = (
|
|
15
35
|
title: string,
|
|
16
36
|
description?: string,
|
|
17
37
|
markdown?: string,
|
|
18
|
-
rootDir: string = ""
|
|
38
|
+
rootDir: string = "",
|
|
39
|
+
fileName?: string
|
|
19
40
|
) => {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
41
|
+
// Create the folders needed if they're missing
|
|
42
|
+
mkdirSync(rootDir, { recursive: true });
|
|
43
|
+
|
|
44
|
+
// Write the page to memory
|
|
45
|
+
const writePath = path.join(rootDir, addMdx(fileName || toFilename(title)));
|
|
46
|
+
writeFileSync(writePath, Page(title, description, markdown));
|
|
47
|
+
console.log("✏️ - " + writePath);
|
|
24
48
|
};
|