mintlify 1.0.2 → 1.0.5

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 ADDED
@@ -0,0 +1,7 @@
1
+ # Mintlify CLI
2
+
3
+ To test changes locally run:
4
+
5
+ `npm run build`
6
+ then
7
+ `npm i -g .`
package/bin/index.js CHANGED
@@ -2,12 +2,16 @@
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 { scrapeGitBook } from "./scrapeGitBook.js";
7
+ import { scrapeReadMe } from "./scrapeReadMe.js";
5
8
  const args = process.argv.slice(2);
6
9
  if (args.length === 0) {
7
10
  console.error(`No command specified. Here are is the list that you can use:\ninit: initialize a Mintlify documentation instance`);
8
11
  process.exit(1); //an error occurred
9
12
  }
10
- if (args[0] === "init") {
13
+ const command = args[0];
14
+ if (command === "init") {
11
15
  inquirer
12
16
  .prompt([
13
17
  {
@@ -42,11 +46,52 @@ if (args[0] === "init") {
42
46
  ])
43
47
  .then((answers) => {
44
48
  const { name, color, ctaName, ctaUrl, title } = answers;
45
- writeFileSync("mint.config.json", JSON.stringify(MintConfig(name, color, ctaName, ctaUrl, title), null, "\t"));
49
+ writeFileSync("mint.config.json", JSON.stringify(MintConfig(name, color, ctaName, ctaUrl, toFilename(title)), null, "\t"));
50
+ createPage(title);
51
+ console.log("🌱 Created initial files for Mintlify docs");
52
+ process.exit(1);
46
53
  })
47
54
  .catch((error) => {
48
55
  console.error(error);
49
56
  process.exit(1);
50
57
  });
51
58
  }
59
+ if (command === "page") {
60
+ inquirer
61
+ .prompt([
62
+ {
63
+ type: "input",
64
+ name: "title",
65
+ message: "What is the title of the new page?",
66
+ },
67
+ {
68
+ type: "input",
69
+ name: "description",
70
+ message: "What is the description?",
71
+ default: "",
72
+ },
73
+ ])
74
+ .then((answers) => {
75
+ const { title, description } = answers;
76
+ createPage(title, description);
77
+ console.log("🌱 Created initial files for Mintlify docs");
78
+ process.exit(1);
79
+ })
80
+ .catch((error) => {
81
+ console.error(error);
82
+ process.exit(1);
83
+ });
84
+ }
85
+ if (command === "scrape-gitbook") {
86
+ const url = args[1];
87
+ const { title, description, markdown } = await scrapeGitBook(url);
88
+ createPage(title, description, markdown, process.env.INIT_CWD);
89
+ process.exit(1);
90
+ }
91
+ if (command === "scrape-readme") {
92
+ const url = args[1];
93
+ const { title, description, markdown } = await scrapeReadMe(url);
94
+ createPage(title, description, markdown, process.env.INIT_CWD);
95
+ process.exit(1);
96
+ }
52
97
  //# 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;AAE5C,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAEnC,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE;IACrB,OAAO,CAAC,KAAK,CACX,kHAAkH,CACnH,CAAC;IACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,mBAAmB;CACrC;AAED,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,MAAM,EAAE;IACtB,QAAQ;SACL,MAAM,CAAC;QACN;YACE,IAAI,EAAE,OAAO;YACb,IAAI,EAAE,MAAM;YACZ,OAAO,EAAE,uCAAuC;SACjD;QACD;YACE,IAAI,EAAE,OAAO;YACb,IAAI,EAAE,OAAO;YACb,OAAO,EAAE,yCAAyC;YAClD,OAAO,EAAE,SAAS;SACnB;QACD;YACE,IAAI,EAAE,OAAO;YACb,IAAI,EAAE,SAAS;YACf,OAAO,EAAE,gDAAgD;YACzD,OAAO,EA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/B,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,GAAG,MAAM,YAAY,CAAC,GAAG,CAAC,CAAC;IACjE,UAAU,CAAC,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC/D,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,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,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 scrapeReadMe(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=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,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,GAAW;IAC5C,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.js CHANGED
@@ -1,4 +1,4 @@
1
- export const MintConfig = (name, color, ctaName, ctaUrl, title) => {
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: [title],
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
@@ -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,KAAa,EACb,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,KAAK,CAAC;aACf;SACF;QACD,6DAA6D;KAC9D,CAAC;AACJ,CAAC,CAAC"}
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,15 @@
1
+ import { writeFileSync } from "fs";
2
+ import { Page } from "./templates.js";
3
+ export const toFilename = (title) => {
4
+ // Gets rid of special characters at the start and end
5
+ // of the name by converting to spaces then using trim.
6
+ return title
7
+ .replace(/[^a-z0-9]/gi, " ")
8
+ .trim()
9
+ .replace(/ /g, "-")
10
+ .toLowerCase();
11
+ };
12
+ export const createPage = (title, description, markdown, rootDir = "") => {
13
+ return writeFileSync(rootDir + toFilename(title) + ".mdx", Page(title, description, markdown));
14
+ };
15
+ //# sourceMappingURL=util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AACnC,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAEtC,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,UAAU,GAAG,CACxB,KAAa,EACb,WAAoB,EACpB,QAAiB,EACjB,UAAkB,EAAE,EACpB,EAAE;IACF,OAAO,aAAa,CAClB,OAAO,GAAG,UAAU,CAAC,KAAK,CAAC,GAAG,MAAM,EACpC,IAAI,CAAC,KAAK,EAAE,WAAW,EAAE,QAAQ,CAAC,CACnC,CAAC;AACJ,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mintlify",
3
- "version": "1.0.2",
3
+ "version": "1.0.5",
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
- "inquirer": "^9.1.0"
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
@@ -3,6 +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 { scrapeGitBook } from "./scrapeGitBook.js";
8
+ import { scrapeReadMe } from "./scrapeReadMe.js";
6
9
 
7
10
  const args = process.argv.slice(2);
8
11
 
@@ -13,7 +16,9 @@ if (args.length === 0) {
13
16
  process.exit(1); //an error occurred
14
17
  }
15
18
 
16
- if (args[0] === "init") {
19
+ const command = args[0];
20
+
21
+ if (command === "init") {
17
22
  inquirer
18
23
  .prompt([
19
24
  {
@@ -51,14 +56,59 @@ if (args[0] === "init") {
51
56
  writeFileSync(
52
57
  "mint.config.json",
53
58
  JSON.stringify(
54
- MintConfig(name, color, ctaName, ctaUrl, title),
59
+ MintConfig(name, color, ctaName, ctaUrl, toFilename(title)),
55
60
  null,
56
61
  "\t"
57
62
  )
58
63
  );
64
+ createPage(title);
65
+ console.log("🌱 Created initial files for Mintlify docs");
66
+ process.exit(1);
67
+ })
68
+ .catch((error) => {
69
+ console.error(error);
70
+ process.exit(1);
71
+ });
72
+ }
73
+
74
+ if (command === "page") {
75
+ inquirer
76
+ .prompt([
77
+ {
78
+ type: "input",
79
+ name: "title",
80
+ message: "What is the title of the new page?",
81
+ },
82
+ {
83
+ type: "input",
84
+ name: "description",
85
+ message: "What is the description?",
86
+ default: "",
87
+ },
88
+ ])
89
+ .then((answers) => {
90
+ const { title, description } = answers;
91
+
92
+ createPage(title, description);
93
+ console.log("🌱 Created initial files for Mintlify docs");
94
+ process.exit(1);
59
95
  })
60
96
  .catch((error) => {
61
97
  console.error(error);
62
98
  process.exit(1);
63
99
  });
64
100
  }
101
+
102
+ if (command === "scrape-gitbook") {
103
+ const url = args[1];
104
+ const { title, description, markdown } = await scrapeGitBook(url);
105
+ createPage(title, description, markdown, process.env.INIT_CWD);
106
+ process.exit(1);
107
+ }
108
+
109
+ if (command === "scrape-readme") {
110
+ const url = args[1];
111
+ const { title, description, markdown } = await scrapeReadMe(url);
112
+ createPage(title, description, markdown, process.env.INIT_CWD);
113
+ process.exit(1);
114
+ }
@@ -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 scrapeGitBook(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,37 @@
1
+ import axios from "axios";
2
+ import cheerio from "cheerio";
3
+ import { NodeHtmlMarkdown } from "node-html-markdown";
4
+
5
+ export async function scrapeReadMe(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
@@ -3,7 +3,7 @@ export const MintConfig = (
3
3
  color: string,
4
4
  ctaName: string,
5
5
  ctaUrl: string,
6
- title: string
6
+ filename: string
7
7
  ) => {
8
8
  return {
9
9
  name,
@@ -21,9 +21,32 @@ export const MintConfig = (
21
21
  navigation: [
22
22
  {
23
23
  group: "Home",
24
- pages: [title],
24
+ pages: [filename],
25
25
  },
26
26
  ],
27
27
  // footerSocials: {}, // support object type for footer tyoes
28
28
  };
29
29
  };
30
+
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}`;
52
+ };
package/src/util.ts ADDED
@@ -0,0 +1,24 @@
1
+ import { writeFileSync } from "fs";
2
+ import { Page } from "./templates.js";
3
+
4
+ export const toFilename = (title: string) => {
5
+ // Gets rid of special characters at the start and end
6
+ // of the name by converting to spaces then using trim.
7
+ return title
8
+ .replace(/[^a-z0-9]/gi, " ")
9
+ .trim()
10
+ .replace(/ /g, "-")
11
+ .toLowerCase();
12
+ };
13
+
14
+ export const createPage = (
15
+ title: string,
16
+ description?: string,
17
+ markdown?: string,
18
+ rootDir: string = ""
19
+ ) => {
20
+ return writeFileSync(
21
+ rootDir + toFilename(title) + ".mdx",
22
+ Page(title, description, markdown)
23
+ );
24
+ };
package/tsconfig.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "module": "node16",
4
4
  "moduleResolution": "node16",
5
5
  "target": "es2017",
6
- "lib": ["es2015"],
6
+ "lib": ["es2016", "dom"],
7
7
  "sourceMap": true,
8
8
  "outDir": "bin",
9
9
  "baseUrl": ".",