mintlify 1.0.3 → 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/README.md +7 -0
- package/bin/index.js +57 -2
- package/bin/index.js.map +1 -1
- package/bin/scrapeGitBook.js +28 -0
- package/bin/scrapeGitBook.js.map +1 -0
- package/bin/scrapeGitBookPage.js +28 -0
- package/bin/scrapeGitBookPage.js.map +1 -0
- package/bin/scrapeReadMe.js +60 -0
- package/bin/scrapeReadMe.js.map +1 -0
- package/bin/scrapeReadMePage.js +28 -0
- package/bin/scrapeReadMePage.js.map +1 -0
- package/bin/templates.js +19 -2
- package/bin/templates.js.map +1 -1
- package/bin/util.js +37 -0
- package/bin/util.js.map +1 -0
- package/package.json +6 -2
- package/src/index.ts +31 -3
- package/src/scrapeGitBookPage.ts +36 -0
- package/src/scrapeReadMe.ts +79 -0
- package/src/scrapeReadMePage.ts +37 -0
- package/src/templates.ts +21 -3
- package/src/util.ts +46 -1
- package/tsconfig.json +1 -1
package/README.md
ADDED
package/bin/index.js
CHANGED
|
@@ -2,12 +2,17 @@
|
|
|
2
2
|
import { writeFileSync } from "fs";
|
|
3
3
|
import inquirer from "inquirer";
|
|
4
4
|
import { MintConfig } from "./templates.js";
|
|
5
|
+
import { createPage, toFilename, objToReadableString } from "./util.js";
|
|
6
|
+
import { scrapeGitBookPage } from "./scrapeGitBookPage.js";
|
|
7
|
+
import { scrapeReadMePage } from "./scrapeReadMePage.js";
|
|
8
|
+
import { scrapeReadMe } from "./scrapeReadMe.js";
|
|
5
9
|
const args = process.argv.slice(2);
|
|
6
10
|
if (args.length === 0) {
|
|
7
11
|
console.error(`No command specified. Here are is the list that you can use:\ninit: initialize a Mintlify documentation instance`);
|
|
8
12
|
process.exit(1); //an error occurred
|
|
9
13
|
}
|
|
10
|
-
|
|
14
|
+
const command = args[0];
|
|
15
|
+
if (command === "init") {
|
|
11
16
|
inquirer
|
|
12
17
|
.prompt([
|
|
13
18
|
{
|
|
@@ -42,11 +47,61 @@ if (args[0] === "init") {
|
|
|
42
47
|
])
|
|
43
48
|
.then((answers) => {
|
|
44
49
|
const { name, color, ctaName, ctaUrl, title } = answers;
|
|
45
|
-
writeFileSync("mint.config.json", JSON.stringify(MintConfig(name, color, ctaName, ctaUrl, title), null, "\t"));
|
|
50
|
+
writeFileSync("mint.config.json", JSON.stringify(MintConfig(name, color, ctaName, ctaUrl, toFilename(title)), null, "\t"));
|
|
51
|
+
createPage(title);
|
|
52
|
+
console.log("🌱 Created initial files for Mintlify docs");
|
|
53
|
+
process.exit(1);
|
|
54
|
+
})
|
|
55
|
+
.catch((error) => {
|
|
56
|
+
console.error(error);
|
|
57
|
+
process.exit(1);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
if (command === "page") {
|
|
61
|
+
inquirer
|
|
62
|
+
.prompt([
|
|
63
|
+
{
|
|
64
|
+
type: "input",
|
|
65
|
+
name: "title",
|
|
66
|
+
message: "What is the title of the new page?",
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
type: "input",
|
|
70
|
+
name: "description",
|
|
71
|
+
message: "What is the description?",
|
|
72
|
+
default: "",
|
|
73
|
+
},
|
|
74
|
+
])
|
|
75
|
+
.then((answers) => {
|
|
76
|
+
const { title, description } = answers;
|
|
77
|
+
createPage(title, description);
|
|
78
|
+
console.log("🌱 Created initial files for Mintlify docs");
|
|
79
|
+
process.exit(1);
|
|
46
80
|
})
|
|
47
81
|
.catch((error) => {
|
|
48
82
|
console.error(error);
|
|
49
83
|
process.exit(1);
|
|
50
84
|
});
|
|
51
85
|
}
|
|
86
|
+
if (command === "scrape-gitbook-page") {
|
|
87
|
+
const url = args[1];
|
|
88
|
+
const { title, description, markdown } = await scrapeGitBookPage(url);
|
|
89
|
+
createPage(title, description, markdown, process.cwd());
|
|
90
|
+
process.exit(1);
|
|
91
|
+
}
|
|
92
|
+
if (command === "scrape-readme-page") {
|
|
93
|
+
const url = args[1];
|
|
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));
|
|
105
|
+
process.exit(1);
|
|
106
|
+
}
|
|
52
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;
|
|
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;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAEnC,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE;IACrB,OAAO,CAAC,KAAK,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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 scrapeGitBook(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=scrapeGitBook.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scrapeGitBook.js","sourceRoot":"","sources":["../src/scrapeGitBook.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,aAAa,CAAC,GAAW;IAC7C,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,GAAG,CAAC,CAAC,4BAA4B,CAAC,CAAC,KAAK,EAAE,CAAC;IAC/D,MAAM,mBAAmB,GAAG,cAAc,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC;IAC7E,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;IACjC,MAAM,WAAW,GAAG,mBAAmB;SACpC,OAAO,CAAC,cAAc,CAAC,IAAI,EAAE,EAAE,EAAE,CAAC;SAClC,IAAI,EAAE,CAAC;IACV,MAAM,KAAK,GAAG,cAAc,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC;IAE3C,MAAM,OAAO,GAAG,CAAC,CAAC,oCAAoC,CAAC,CAAC,KAAK,EAAE,CAAC;IAChE,MAAM,WAAW,GAAG,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAEpC,MAAM,GAAG,GAAG,IAAI,gBAAgB,EAAE,CAAC;IACnC,IAAI,QAAQ,GAAG,GAAG,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IAE1C,2DAA2D;IAC3D,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IAE9C,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;IAEjE,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC;AAC1C,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 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,GAAG,CAAC,CAAC,4BAA4B,CAAC,CAAC,KAAK,EAAE,CAAC;IAC/D,MAAM,mBAAmB,GAAG,cAAc,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC;IAC7E,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;IACjC,MAAM,WAAW,GAAG,mBAAmB;SACpC,OAAO,CAAC,cAAc,CAAC,IAAI,EAAE,EAAE,EAAE,CAAC;SAClC,IAAI,EAAE,CAAC;IACV,MAAM,KAAK,GAAG,cAAc,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC;IAE3C,MAAM,OAAO,GAAG,CAAC,CAAC,oCAAoC,CAAC,CAAC,KAAK,EAAE,CAAC;IAChE,MAAM,WAAW,GAAG,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAEpC,MAAM,GAAG,GAAG,IAAI,gBAAgB,EAAE,CAAC;IACnC,IAAI,QAAQ,GAAG,GAAG,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IAE1C,2DAA2D;IAC3D,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IAE9C,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;IAEjE,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC;AAC1C,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import cheerio from "cheerio";
|
|
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) {
|
|
7
|
+
const res = await axios.default.get(url);
|
|
8
|
+
const $ = cheerio.load(res.data);
|
|
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
|
+
}));
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=scrapeReadMe.js.map
|
|
@@ -0,0 +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,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,UAAU,EAAU,MAAM,WAAW,CAAC;AAE3D,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,GAAW,EAAE,MAAc;IAC5D,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;IACjC,MAAM,OAAO,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC;IAEhC,kCAAkC;IAClC,MAAM,kBAAkB,GAAG,CAAC,CAAC,qBAAqB,CAAC,CAAC;IAEpD,MAAM,YAAY,GAAG,kBAAkB;SACpC,GAAG,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE;QAClB,MAAM,YAAY,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,CAAC;QAC1D,MAAM,SAAS,GAAG,CAAC,CAAC,OAAO,CAAC;aACzB,IAAI,CAAC,SAAS,CAAC;aACf,GAAG,C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C,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;YAEtE,2DAA2D;YAC3D,MAAM,QAAQ,GACZ,YAAY,CAAC,MAAM,KAAK,CAAC;gBACvB,CAAC,CAAC,cAAc;gBAChB,CAAC,CAAC,YAAY,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;YAE5C,mCAAmC;YACnC,UAAU,CAAC,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,eAAe,EAAE,QAAQ,CAAC,CAAC;YAEpE,sEAAsE;YACtE,OAAO,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;QACxE,CAAC,CAAC,CACH,CAAC;QACF,OAAO,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,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,GAAW;IAChD,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,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,CAAC;IACvC,MAAM,KAAK,GAAG,cAAc,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC;IAC3C,MAAM,WAAW,GAAG,CAAC,CAAC,gBAAgB,EAAE,cAAc,CAAC,MAAM,EAAE,CAAC;SAC7D,IAAI,EAAE;SACN,IAAI,EAAE,CAAC;IAEV,MAAM,OAAO,GAAG,CAAC,CAAC,8BAA8B,CAAC,CAAC,KAAK,EAAE,CAAC;IAC1D,MAAM,WAAW,GAAG,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAEpC,MAAM,GAAG,GAAG,IAAI,gBAAgB,EAAE,CAAC;IACnC,IAAI,QAAQ,GAAG,GAAG,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IAE1C,2DAA2D;IAC3D,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IAE9C,qDAAqD;IACrD,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;IAE3C,6BAA6B;IAC7B,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,kBAAkB,EAAE,IAAI,CAAC,CAAC;IAEtD,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;IAEjE,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC;AAC1C,CAAC"}
|
package/bin/templates.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const MintConfig = (name, color, ctaName, ctaUrl,
|
|
1
|
+
export const MintConfig = (name, color, ctaName, ctaUrl, filename) => {
|
|
2
2
|
return {
|
|
3
3
|
name,
|
|
4
4
|
logo: "",
|
|
@@ -15,10 +15,27 @@ export const MintConfig = (name, color, ctaName, ctaUrl, title) => {
|
|
|
15
15
|
navigation: [
|
|
16
16
|
{
|
|
17
17
|
group: "Home",
|
|
18
|
-
pages: [
|
|
18
|
+
pages: [filename],
|
|
19
19
|
},
|
|
20
20
|
],
|
|
21
21
|
// footerSocials: {}, // support object type for footer tyoes
|
|
22
22
|
};
|
|
23
23
|
};
|
|
24
|
+
export const Page = (title, description, markdown) => {
|
|
25
|
+
// If we are an empty String we want to add two quotes,
|
|
26
|
+
// if we added as we went we would detect the first quote
|
|
27
|
+
// as the closing quote.
|
|
28
|
+
const startsWithQuote = title.startsWith('"');
|
|
29
|
+
const endsWithQuote = title.startsWith('"');
|
|
30
|
+
if (!startsWithQuote) {
|
|
31
|
+
title = '"' + title;
|
|
32
|
+
}
|
|
33
|
+
if (!endsWithQuote) {
|
|
34
|
+
title = title + '"';
|
|
35
|
+
}
|
|
36
|
+
const optionalDescription = description
|
|
37
|
+
? `\ndescription: "${description}"`
|
|
38
|
+
: "";
|
|
39
|
+
return `---\ntitle: ${title}${optionalDescription}\n---\n\n${markdown}`;
|
|
40
|
+
};
|
|
24
41
|
//# sourceMappingURL=templates.js.map
|
package/bin/templates.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"templates.js","sourceRoot":"","sources":["../src/templates.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,UAAU,GAAG,CACxB,IAAY,EACZ,KAAa,EACb,OAAe,EACf,MAAc,EACd,
|
|
1
|
+
{"version":3,"file":"templates.js","sourceRoot":"","sources":["../src/templates.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,UAAU,GAAG,CACxB,IAAY,EACZ,KAAa,EACb,OAAe,EACf,MAAc,EACd,QAAgB,EAChB,EAAE;IACF,OAAO;QACL,IAAI;QACJ,IAAI,EAAE,EAAE;QACR,OAAO,EAAE,EAAE;QACX,MAAM,EAAE;YACN,OAAO,EAAE,KAAK;SACf;QACD,WAAW,EAAE,EAAE;QACf,eAAe,EAAE;YACf,IAAI,EAAE,OAAO;YACb,GAAG,EAAE,MAAM;SACZ;QACD,OAAO,EAAE,EAAE;QACX,UAAU,EAAE;YACV;gBACE,KAAK,EAAE,MAAM;gBACb,KAAK,EAAE,CAAC,QAAQ,CAAC;aAClB;SACF;QACD,6DAA6D;KAC9D,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,IAAI,GAAG,CAClB,KAAa,EACb,WAAoB,EACpB,QAAiB,EACjB,EAAE;IACF,uDAAuD;IACvD,yDAAyD;IACzD,wBAAwB;IACxB,MAAM,eAAe,GAAG,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IAC9C,MAAM,aAAa,GAAG,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IAC5C,IAAI,CAAC,eAAe,EAAE;QACpB,KAAK,GAAG,GAAG,GAAG,KAAK,CAAC;KACrB;IACD,IAAI,CAAC,aAAa,EAAE;QAClB,KAAK,GAAG,KAAK,GAAG,GAAG,CAAC;KACrB;IAED,MAAM,mBAAmB,GAAG,WAAW;QACrC,CAAC,CAAC,mBAAmB,WAAW,GAAG;QACnC,CAAC,CAAC,EAAE,CAAC;IACP,OAAO,eAAe,KAAK,GAAG,mBAAmB,YAAY,QAAQ,EAAE,CAAC;AAC1E,CAAC,CAAC"}
|
package/bin/util.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { mkdirSync, writeFileSync } from "fs";
|
|
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
|
+
}
|
|
14
|
+
export const toFilename = (title) => {
|
|
15
|
+
// Gets rid of special characters at the start and end
|
|
16
|
+
// of the name by converting to spaces then using trim.
|
|
17
|
+
return title
|
|
18
|
+
.replace(/[^a-z0-9]/gi, " ")
|
|
19
|
+
.trim()
|
|
20
|
+
.replace(/ /g, "-")
|
|
21
|
+
.toLowerCase();
|
|
22
|
+
};
|
|
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);
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=util.js.map
|
package/bin/util.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mintlify",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "Mintlify CLI",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=14.16"
|
|
@@ -16,7 +16,11 @@
|
|
|
16
16
|
},
|
|
17
17
|
"type": "module",
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"
|
|
19
|
+
"axios": "^0.27.2",
|
|
20
|
+
"cheerio": "^0.22.0",
|
|
21
|
+
"inquirer": "^9.1.0",
|
|
22
|
+
"node-html-markdown": "^1.2.0",
|
|
23
|
+
"puppeteer": "^17.1.2"
|
|
20
24
|
},
|
|
21
25
|
"devDependencies": {
|
|
22
26
|
"@types/inquirer": "^9.0.1",
|
package/src/index.ts
CHANGED
|
@@ -2,8 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
import { writeFileSync } from "fs";
|
|
4
4
|
import inquirer from "inquirer";
|
|
5
|
-
import { MintConfig
|
|
6
|
-
import { toFilename } from "./util.js";
|
|
5
|
+
import { MintConfig } from "./templates.js";
|
|
6
|
+
import { createPage, toFilename, objToReadableString } from "./util.js";
|
|
7
|
+
import { scrapeGitBookPage } from "./scrapeGitBookPage.js";
|
|
8
|
+
import { scrapeReadMePage } from "./scrapeReadMePage.js";
|
|
9
|
+
import { scrapeReadMe } from "./scrapeReadMe.js";
|
|
7
10
|
|
|
8
11
|
const args = process.argv.slice(2);
|
|
9
12
|
|
|
@@ -59,6 +62,7 @@ if (command === "init") {
|
|
|
59
62
|
"\t"
|
|
60
63
|
)
|
|
61
64
|
);
|
|
65
|
+
createPage(title);
|
|
62
66
|
console.log("🌱 Created initial files for Mintlify docs");
|
|
63
67
|
process.exit(1);
|
|
64
68
|
})
|
|
@@ -86,7 +90,7 @@ if (command === "page") {
|
|
|
86
90
|
.then((answers) => {
|
|
87
91
|
const { title, description } = answers;
|
|
88
92
|
|
|
89
|
-
|
|
93
|
+
createPage(title, description);
|
|
90
94
|
console.log("🌱 Created initial files for Mintlify docs");
|
|
91
95
|
process.exit(1);
|
|
92
96
|
})
|
|
@@ -95,3 +99,27 @@ if (command === "page") {
|
|
|
95
99
|
process.exit(1);
|
|
96
100
|
});
|
|
97
101
|
}
|
|
102
|
+
|
|
103
|
+
if (command === "scrape-gitbook-page") {
|
|
104
|
+
const url = args[1];
|
|
105
|
+
const { title, description, markdown } = await scrapeGitBookPage(url);
|
|
106
|
+
createPage(title, description, markdown, process.cwd());
|
|
107
|
+
process.exit(1);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (command === "scrape-readme-page") {
|
|
111
|
+
const url = args[1];
|
|
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));
|
|
124
|
+
process.exit(1);
|
|
125
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import cheerio from "cheerio";
|
|
3
|
+
import { NodeHtmlMarkdown } from "node-html-markdown";
|
|
4
|
+
|
|
5
|
+
export async function scrapeGitBookPage(url: string) {
|
|
6
|
+
const res = await axios.default.get(url);
|
|
7
|
+
const $ = cheerio.load(res.data);
|
|
8
|
+
|
|
9
|
+
const titleComponent = $('[data-testid="page.title"]').first();
|
|
10
|
+
const titleAndDescription = titleComponent.parent().parent().parent().text();
|
|
11
|
+
console.log(titleAndDescription);
|
|
12
|
+
const description = titleAndDescription
|
|
13
|
+
.replace(titleComponent.text(), "")
|
|
14
|
+
.trim();
|
|
15
|
+
const title = titleComponent.text().trim();
|
|
16
|
+
|
|
17
|
+
const content = $('[data-testid="page.contentEditor"]').first();
|
|
18
|
+
const contentHtml = $.html(content);
|
|
19
|
+
|
|
20
|
+
const nhm = new NodeHtmlMarkdown();
|
|
21
|
+
let markdown = nhm.translate(contentHtml);
|
|
22
|
+
|
|
23
|
+
// Keep headers on one line and increase their depth by one
|
|
24
|
+
markdown = markdown.replace(/# \n\n/g, "## ");
|
|
25
|
+
|
|
26
|
+
// Remove unnecessary nonwidth blank space characters
|
|
27
|
+
markdown = markdown.replace(/\u200b/g, "");
|
|
28
|
+
|
|
29
|
+
// Reduce unnecessary blank lines
|
|
30
|
+
markdown = markdown.replace(/\n\n\n/g, "\n\n");
|
|
31
|
+
|
|
32
|
+
// Mintlify doesn't support bolded headers, remove the asterisks
|
|
33
|
+
markdown = markdown.replace(/(\n#+) \*\*(.*)\*\*\n/g, "$1 $2\n");
|
|
34
|
+
|
|
35
|
+
return { title, description, markdown };
|
|
36
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import cheerio from "cheerio";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import { scrapeReadMePage } from "./scrapeReadMePage.js";
|
|
5
|
+
import { createPage, getWebsite, addMdx } from "./util.js";
|
|
6
|
+
|
|
7
|
+
export async function scrapeReadMe(url: string, cliDir: string) {
|
|
8
|
+
const res = await axios.default.get(url);
|
|
9
|
+
const $ = cheerio.load(res.data);
|
|
10
|
+
const website = getWebsite(url);
|
|
11
|
+
|
|
12
|
+
// Get all the navigation sections
|
|
13
|
+
const navigationSections = $(".rm-Sidebar-section");
|
|
14
|
+
|
|
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");
|
|
22
|
+
|
|
23
|
+
// Skip external links until Mintlify supports them
|
|
24
|
+
if (href.startsWith("https://") || href.startsWith("http://")) {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return href;
|
|
29
|
+
})
|
|
30
|
+
.toArray();
|
|
31
|
+
|
|
32
|
+
// Follows the same structure as mint.config.js
|
|
33
|
+
return {
|
|
34
|
+
group: sectionTitle,
|
|
35
|
+
pages: linkPaths,
|
|
36
|
+
};
|
|
37
|
+
})
|
|
38
|
+
.toArray();
|
|
39
|
+
|
|
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
|
+
);
|
|
48
|
+
|
|
49
|
+
// Removes file name from the end
|
|
50
|
+
const splitSubpath = page.split("/");
|
|
51
|
+
let folders = splitSubpath
|
|
52
|
+
.slice(0, splitSubpath.length - 1)
|
|
53
|
+
.join("/");
|
|
54
|
+
|
|
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
|
+
}
|
|
60
|
+
|
|
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
|
+
);
|
|
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/templates.ts
CHANGED
|
@@ -28,7 +28,25 @@ export const MintConfig = (
|
|
|
28
28
|
};
|
|
29
29
|
};
|
|
30
30
|
|
|
31
|
-
export const Page = (
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
export const Page = (
|
|
32
|
+
title: string,
|
|
33
|
+
description?: string,
|
|
34
|
+
markdown?: string
|
|
35
|
+
) => {
|
|
36
|
+
// If we are an empty String we want to add two quotes,
|
|
37
|
+
// if we added as we went we would detect the first quote
|
|
38
|
+
// as the closing quote.
|
|
39
|
+
const startsWithQuote = title.startsWith('"');
|
|
40
|
+
const endsWithQuote = title.startsWith('"');
|
|
41
|
+
if (!startsWithQuote) {
|
|
42
|
+
title = '"' + title;
|
|
43
|
+
}
|
|
44
|
+
if (!endsWithQuote) {
|
|
45
|
+
title = title + '"';
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const optionalDescription = description
|
|
49
|
+
? `\ndescription: "${description}"`
|
|
50
|
+
: "";
|
|
51
|
+
return `---\ntitle: ${title}${optionalDescription}\n---\n\n${markdown}`;
|
|
34
52
|
};
|
package/src/util.ts
CHANGED
|
@@ -1,3 +1,48 @@
|
|
|
1
|
+
import { mkdirSync, writeFileSync } from "fs";
|
|
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
|
+
}
|
|
16
|
+
|
|
1
17
|
export const toFilename = (title: string) => {
|
|
2
|
-
|
|
18
|
+
// Gets rid of special characters at the start and end
|
|
19
|
+
// of the name by converting to spaces then using trim.
|
|
20
|
+
return title
|
|
21
|
+
.replace(/[^a-z0-9]/gi, " ")
|
|
22
|
+
.trim()
|
|
23
|
+
.replace(/ /g, "-")
|
|
24
|
+
.toLowerCase();
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const addMdx = (fileName: string) => {
|
|
28
|
+
if (fileName.endsWith(".mdx")) {
|
|
29
|
+
return fileName;
|
|
30
|
+
}
|
|
31
|
+
return fileName + ".mdx";
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export const createPage = (
|
|
35
|
+
title: string,
|
|
36
|
+
description?: string,
|
|
37
|
+
markdown?: string,
|
|
38
|
+
rootDir: string = "",
|
|
39
|
+
fileName?: string
|
|
40
|
+
) => {
|
|
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);
|
|
3
48
|
};
|