@mintlify/previewing 3.1.56 → 3.1.57

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/LICENSE +93 -0
  2. package/README.md +17 -17
  3. package/dist/constants.d.ts +9 -9
  4. package/dist/constants.js +31 -31
  5. package/dist/downloadImage.d.ts +4 -4
  6. package/dist/downloadImage.js +139 -139
  7. package/dist/index.d.ts +3 -3
  8. package/dist/index.js +3 -3
  9. package/dist/local-preview/helper-commands/installDepsCommand.d.ts +2 -2
  10. package/dist/local-preview/helper-commands/installDepsCommand.js +51 -51
  11. package/dist/local-preview/index.d.ts +3 -3
  12. package/dist/local-preview/index.js +212 -212
  13. package/dist/local-preview/listener/categorize.d.ts +8 -8
  14. package/dist/local-preview/listener/categorize.js +193 -193
  15. package/dist/local-preview/listener/generate.d.ts +1 -1
  16. package/dist/local-preview/listener/generate.js +137 -137
  17. package/dist/local-preview/listener/index.d.ts +2 -2
  18. package/dist/local-preview/listener/index.js +317 -317
  19. package/dist/local-preview/listener/update.d.ts +2 -2
  20. package/dist/local-preview/listener/update.js +79 -79
  21. package/dist/local-preview/listener/utils/createPage.d.ts +10 -10
  22. package/dist/local-preview/listener/utils/createPage.js +210 -210
  23. package/dist/local-preview/listener/utils/getOpenApiContext.d.ts +21 -21
  24. package/dist/local-preview/listener/utils/getOpenApiContext.js +55 -55
  25. package/dist/local-preview/listener/utils/mintConfigFile.d.ts +2 -2
  26. package/dist/local-preview/listener/utils/mintConfigFile.js +74 -74
  27. package/dist/local-preview/listener/utils/types.d.ts +2 -2
  28. package/dist/local-preview/listener/utils/types.js +1 -1
  29. package/dist/local-preview/listener/utils.d.ts +13 -13
  30. package/dist/local-preview/listener/utils.js +112 -112
  31. package/dist/tsconfig.tsbuildinfo +1 -1
  32. package/dist/util.d.ts +4 -4
  33. package/dist/util.js +20 -20
  34. package/package.json +88 -87
@@ -1,79 +1,79 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- var __generator = (this && this.__generator) || function (thisArg, body) {
11
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
- function verb(n) { return function (v) { return step([n, v]); }; }
14
- function step(op) {
15
- if (f) throw new TypeError("Generator is already executing.");
16
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
- if (y = 0, t) op = [op[0] & 2, t.value];
19
- switch (op[0]) {
20
- case 0: case 1: t = op; break;
21
- case 4: _.label++; return { value: op[1], done: false };
22
- case 5: _.label++; y = op[1]; op = [0]; continue;
23
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
- default:
25
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
- if (t[2]) _.ops.pop();
30
- _.trys.pop(); continue;
31
- }
32
- op = body.call(thisArg, _);
33
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
- }
36
- };
37
- // TODO: Add Types
38
- import { promises as _promises } from 'fs';
39
- import fse from 'fs-extra';
40
- import { join } from 'path';
41
- import { CLIENT_PATH, CMD_EXEC_PATH } from '../../constants.js';
42
- import { categorizeFiles } from './categorize.js';
43
- import { generateNav } from './generate.js';
44
- var readFile = _promises.readFile;
45
- // TODO: Put in prebuild package
46
- export var updateGeneratedNav = function () { return __awaiter(void 0, void 0, void 0, function () {
47
- var generatedNav, targetPath;
48
- return __generator(this, function (_a) {
49
- switch (_a.label) {
50
- case 0: return [4 /*yield*/, generateNav()];
51
- case 1:
52
- generatedNav = _a.sent();
53
- targetPath = join(CLIENT_PATH, 'src', '_props', 'generatedNav.json');
54
- return [4 /*yield*/, fse.outputFile(targetPath, JSON.stringify(generatedNav, null, 2), {
55
- flag: 'w',
56
- })];
57
- case 2:
58
- _a.sent();
59
- return [2 /*return*/];
60
- }
61
- });
62
- }); };
63
- export var updateOpenApiFiles = function () { return __awaiter(void 0, void 0, void 0, function () {
64
- var openApiFiles, targetPath;
65
- return __generator(this, function (_a) {
66
- switch (_a.label) {
67
- case 0: return [4 /*yield*/, categorizeFiles(CMD_EXEC_PATH)];
68
- case 1:
69
- openApiFiles = (_a.sent()).openApiFiles;
70
- targetPath = join(CLIENT_PATH, 'src', '_props', 'openApiFiles.json');
71
- return [4 /*yield*/, fse.outputFile(targetPath, JSON.stringify(openApiFiles, null, 2), {
72
- flag: 'w',
73
- })];
74
- case 2:
75
- _a.sent();
76
- return [2 /*return*/];
77
- }
78
- });
79
- }); };
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
37
+ // TODO: Add Types
38
+ import { promises as _promises } from 'fs';
39
+ import fse from 'fs-extra';
40
+ import { join } from 'path';
41
+ import { CLIENT_PATH, CMD_EXEC_PATH } from '../../constants.js';
42
+ import { categorizeFiles } from './categorize.js';
43
+ import { generateNav } from './generate.js';
44
+ var readFile = _promises.readFile;
45
+ // TODO: Put in prebuild package
46
+ export var updateGeneratedNav = function () { return __awaiter(void 0, void 0, void 0, function () {
47
+ var generatedNav, targetPath;
48
+ return __generator(this, function (_a) {
49
+ switch (_a.label) {
50
+ case 0: return [4 /*yield*/, generateNav()];
51
+ case 1:
52
+ generatedNav = _a.sent();
53
+ targetPath = join(CLIENT_PATH, 'src', '_props', 'generatedNav.json');
54
+ return [4 /*yield*/, fse.outputFile(targetPath, JSON.stringify(generatedNav, null, 2), {
55
+ flag: 'w',
56
+ })];
57
+ case 2:
58
+ _a.sent();
59
+ return [2 /*return*/];
60
+ }
61
+ });
62
+ }); };
63
+ export var updateOpenApiFiles = function () { return __awaiter(void 0, void 0, void 0, function () {
64
+ var openApiFiles, targetPath;
65
+ return __generator(this, function (_a) {
66
+ switch (_a.label) {
67
+ case 0: return [4 /*yield*/, categorizeFiles(CMD_EXEC_PATH)];
68
+ case 1:
69
+ openApiFiles = (_a.sent()).openApiFiles;
70
+ targetPath = join(CLIENT_PATH, 'src', '_props', 'openApiFiles.json');
71
+ return [4 /*yield*/, fse.outputFile(targetPath, JSON.stringify(openApiFiles, null, 2), {
72
+ flag: 'w',
73
+ })];
74
+ case 2:
75
+ _a.sent();
76
+ return [2 /*return*/];
77
+ }
78
+ });
79
+ }); };
@@ -1,10 +1,10 @@
1
- declare const createPage: (pagePath: string, pageContent: string, contentDirectoryPath: string, openApiFiles: OpenApiFile[]) => Promise<{
2
- pageMetadata: {
3
- href: string;
4
- title: string;
5
- description: string | undefined;
6
- };
7
- pageContent: string;
8
- slug: string;
9
- }>;
10
- export default createPage;
1
+ declare const createPage: (pagePath: string, pageContent: string, contentDirectoryPath: string, openApiFiles: OpenApiFile[]) => Promise<{
2
+ pageMetadata: {
3
+ href: string;
4
+ title: string;
5
+ description: string | undefined;
6
+ };
7
+ pageContent: string;
8
+ slug: string;
9
+ }>;
10
+ export default createPage;
@@ -1,210 +1,210 @@
1
- var __assign = (this && this.__assign) || function () {
2
- __assign = Object.assign || function(t) {
3
- for (var s, i = 1, n = arguments.length; i < n; i++) {
4
- s = arguments[i];
5
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
- t[p] = s[p];
7
- }
8
- return t;
9
- };
10
- return __assign.apply(this, arguments);
11
- };
12
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
- return new (P || (P = Promise))(function (resolve, reject) {
15
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
- step((generator = generator.apply(thisArg, _arguments || [])).next());
19
- });
20
- };
21
- var __generator = (this && this.__generator) || function (thisArg, body) {
22
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
23
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24
- function verb(n) { return function (v) { return step([n, v]); }; }
25
- function step(op) {
26
- if (f) throw new TypeError("Generator is already executing.");
27
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
28
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
29
- if (y = 0, t) op = [op[0] & 2, t.value];
30
- switch (op[0]) {
31
- case 0: case 1: t = op; break;
32
- case 4: _.label++; return { value: op[1], done: false };
33
- case 5: _.label++; y = op[1]; op = [0]; continue;
34
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
35
- default:
36
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40
- if (t[2]) _.ops.pop();
41
- _.trys.pop(); continue;
42
- }
43
- op = body.call(thisArg, _);
44
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
- }
47
- };
48
- import { slugToTitle, optionallyAddLeadingSlash } from '@mintlify/prebuild';
49
- import matter from 'gray-matter';
50
- import isAbsoluteUrl from 'is-absolute-url';
51
- import { remark } from 'remark';
52
- import remarkFrontmatter from 'remark-frontmatter';
53
- import remarkGfm from 'remark-gfm';
54
- import remarkMdx from 'remark-mdx';
55
- import { visit } from 'unist-util-visit';
56
- var createPage = function (pagePath, pageContent, contentDirectoryPath, openApiFiles) { return __awaiter(void 0, void 0, void 0, function () {
57
- var metadata, error_1, slug, defaultTitle, description, _a, title, openApiDescription, pageMetadata;
58
- return __generator(this, function (_b) {
59
- switch (_b.label) {
60
- case 0:
61
- metadata = matter(pageContent).data;
62
- _b.label = 1;
63
- case 1:
64
- _b.trys.push([1, 3, , 4]);
65
- return [4 /*yield*/, preParseMdx(pageContent, contentDirectoryPath)];
66
- case 2:
67
- pageContent = _b.sent();
68
- return [3 /*break*/, 4];
69
- case 3:
70
- error_1 = _b.sent();
71
- pageContent = "\uD83D\uDEA7 A parsing error occured. Please contact the owner of this website.";
72
- return [3 /*break*/, 4];
73
- case 4:
74
- slug = pagePath.replace(/\.mdx?$/, '');
75
- defaultTitle = slugToTitle(slug);
76
- // Append data from OpenAPI if it exists
77
- if (metadata === null || metadata === void 0 ? void 0 : metadata.openapi) {
78
- _a = getOpenApiTitleAndDescription(openApiFiles, metadata === null || metadata === void 0 ? void 0 : metadata.openapi), title = _a.title, openApiDescription = _a.description;
79
- if (title) {
80
- defaultTitle = title;
81
- }
82
- if (openApiDescription) {
83
- description = openApiDescription;
84
- }
85
- }
86
- pageMetadata = __assign(__assign({ title: defaultTitle, description: description }, metadata), { href: optionallyAddLeadingSlash(slug) });
87
- return [2 /*return*/, {
88
- pageMetadata: pageMetadata,
89
- pageContent: pageContent,
90
- slug: removeLeadingSlash(slug),
91
- }];
92
- }
93
- });
94
- }); };
95
- var preParseMdx = function (fileContent, contentDirectoryPath) { return __awaiter(void 0, void 0, void 0, function () {
96
- var removeContentDirectoryPath, removeContentDirectoryPaths, file;
97
- return __generator(this, function (_a) {
98
- switch (_a.label) {
99
- case 0:
100
- removeContentDirectoryPath = function (filePath) {
101
- var pathArr = createPathArr(filePath);
102
- var contentDirectoryPathArr = createPathArr(contentDirectoryPath);
103
- contentDirectoryPathArr.reverse().forEach(function (dir, index) {
104
- if (pathArr[index] === dir) {
105
- pathArr.pop();
106
- }
107
- });
108
- return '/' + pathArr.join('/');
109
- };
110
- removeContentDirectoryPaths = function () {
111
- return function (tree) {
112
- visit(tree, function (node) {
113
- if (node == null) {
114
- return;
115
- }
116
- if (node.name === 'img' || node.name === 'source') {
117
- var srcAttrIndex = node.attributes.findIndex(function (attr) { return (attr === null || attr === void 0 ? void 0 : attr.name) === 'src'; });
118
- var nodeUrl = node.attributes[srcAttrIndex].value;
119
- if (
120
- // <img/> component
121
- srcAttrIndex !== -1 &&
122
- !isAbsoluteUrl(nodeUrl) &&
123
- !isDataString(nodeUrl)) {
124
- node.attributes[srcAttrIndex].value = removeContentDirectoryPath(nodeUrl);
125
- }
126
- }
127
- else if (
128
- // ![]() format
129
- node.type === 'image' &&
130
- node.url &&
131
- !isAbsoluteUrl(node.url) &&
132
- !isDataString(node.url)) {
133
- node.url = removeContentDirectoryPath(node.url);
134
- }
135
- });
136
- return tree;
137
- };
138
- };
139
- return [4 /*yield*/, remark()
140
- .use(remarkMdx)
141
- .use(remarkGfm)
142
- .use(remarkFrontmatter, ['yaml', 'toml'])
143
- .use(removeContentDirectoryPaths)
144
- .process(fileContent)];
145
- case 1:
146
- file = _a.sent();
147
- return [2 /*return*/, String(file)];
148
- }
149
- });
150
- }); };
151
- var removeLeadingSlash = function (str) {
152
- var path = createPathArr(str);
153
- return path.join('/');
154
- };
155
- var createPathArr = function (path) {
156
- return path.split('/').filter(function (dir) { return dir !== ''; });
157
- };
158
- var isDataString = function (str) { return str.startsWith('data:'); };
159
- var getOpenApiTitleAndDescription = function (openApiFiles, openApiMetaField) {
160
- var operation = getOpenApiOperationMethodAndEndpoint(openApiFiles, openApiMetaField).operation;
161
- if (operation == null) {
162
- return {};
163
- }
164
- return {
165
- title: operation.summary,
166
- description: operation.description,
167
- };
168
- };
169
- var getOpenApiOperationMethodAndEndpoint = function (openApiFiles, openApiMetaField) {
170
- var _a = extractMethodAndEndpoint(openApiMetaField), endpoint = _a.endpoint, method = _a.method, filename = _a.filename;
171
- var path;
172
- openApiFiles === null || openApiFiles === void 0 ? void 0 : openApiFiles.forEach(function (file) {
173
- var openApiFile = file.spec;
174
- var openApiPath = openApiFile.paths && openApiFile.paths[endpoint];
175
- var isFilenameOrNone = !filename || filename === file.filename;
176
- if (openApiPath && isFilenameOrNone) {
177
- path = openApiPath;
178
- }
179
- });
180
- if (path == null) {
181
- return {};
182
- }
183
- var operation;
184
- if (method) {
185
- operation = path[method.toLowerCase()];
186
- }
187
- else {
188
- var firstOperationKey = Object.keys(path)[0];
189
- operation = path[firstOperationKey];
190
- }
191
- return {
192
- operation: operation,
193
- method: method,
194
- endpoint: endpoint,
195
- };
196
- };
197
- var extractMethodAndEndpoint = function (openApiMetaField) {
198
- var methodRegex = /(get|post|put|delete|patch)\s/i;
199
- var trimmed = openApiMetaField.trim();
200
- var foundMethod = trimmed.match(methodRegex);
201
- var startIndexOfMethod = foundMethod ? openApiMetaField.indexOf(foundMethod[0]) : 0;
202
- var endIndexOfMethod = foundMethod ? startIndexOfMethod + foundMethod[0].length - 1 : 0;
203
- var filename = openApiMetaField.substring(0, startIndexOfMethod).trim();
204
- return {
205
- method: foundMethod ? foundMethod[0].slice(0, -1).toUpperCase() : undefined,
206
- endpoint: openApiMetaField.substring(endIndexOfMethod).trim(),
207
- filename: filename ? filename : undefined,
208
- };
209
- };
210
- export default createPage;
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
+ return new (P || (P = Promise))(function (resolve, reject) {
15
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
19
+ });
20
+ };
21
+ var __generator = (this && this.__generator) || function (thisArg, body) {
22
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
23
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24
+ function verb(n) { return function (v) { return step([n, v]); }; }
25
+ function step(op) {
26
+ if (f) throw new TypeError("Generator is already executing.");
27
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
28
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
29
+ if (y = 0, t) op = [op[0] & 2, t.value];
30
+ switch (op[0]) {
31
+ case 0: case 1: t = op; break;
32
+ case 4: _.label++; return { value: op[1], done: false };
33
+ case 5: _.label++; y = op[1]; op = [0]; continue;
34
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
35
+ default:
36
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40
+ if (t[2]) _.ops.pop();
41
+ _.trys.pop(); continue;
42
+ }
43
+ op = body.call(thisArg, _);
44
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
+ }
47
+ };
48
+ import { slugToTitle, optionallyAddLeadingSlash } from '@mintlify/prebuild';
49
+ import matter from 'gray-matter';
50
+ import isAbsoluteUrl from 'is-absolute-url';
51
+ import { remark } from 'remark';
52
+ import remarkFrontmatter from 'remark-frontmatter';
53
+ import remarkGfm from 'remark-gfm';
54
+ import remarkMdx from 'remark-mdx';
55
+ import { visit } from 'unist-util-visit';
56
+ var createPage = function (pagePath, pageContent, contentDirectoryPath, openApiFiles) { return __awaiter(void 0, void 0, void 0, function () {
57
+ var metadata, error_1, slug, defaultTitle, description, _a, title, openApiDescription, pageMetadata;
58
+ return __generator(this, function (_b) {
59
+ switch (_b.label) {
60
+ case 0:
61
+ metadata = matter(pageContent).data;
62
+ _b.label = 1;
63
+ case 1:
64
+ _b.trys.push([1, 3, , 4]);
65
+ return [4 /*yield*/, preParseMdx(pageContent, contentDirectoryPath)];
66
+ case 2:
67
+ pageContent = _b.sent();
68
+ return [3 /*break*/, 4];
69
+ case 3:
70
+ error_1 = _b.sent();
71
+ pageContent = "\uD83D\uDEA7 A parsing error occured. Please contact the owner of this website.";
72
+ return [3 /*break*/, 4];
73
+ case 4:
74
+ slug = pagePath.replace(/\.mdx?$/, '');
75
+ defaultTitle = slugToTitle(slug);
76
+ // Append data from OpenAPI if it exists
77
+ if (metadata === null || metadata === void 0 ? void 0 : metadata.openapi) {
78
+ _a = getOpenApiTitleAndDescription(openApiFiles, metadata === null || metadata === void 0 ? void 0 : metadata.openapi), title = _a.title, openApiDescription = _a.description;
79
+ if (title) {
80
+ defaultTitle = title;
81
+ }
82
+ if (openApiDescription) {
83
+ description = openApiDescription;
84
+ }
85
+ }
86
+ pageMetadata = __assign(__assign({ title: defaultTitle, description: description }, metadata), { href: optionallyAddLeadingSlash(slug) });
87
+ return [2 /*return*/, {
88
+ pageMetadata: pageMetadata,
89
+ pageContent: pageContent,
90
+ slug: removeLeadingSlash(slug),
91
+ }];
92
+ }
93
+ });
94
+ }); };
95
+ var preParseMdx = function (fileContent, contentDirectoryPath) { return __awaiter(void 0, void 0, void 0, function () {
96
+ var removeContentDirectoryPath, removeContentDirectoryPaths, file;
97
+ return __generator(this, function (_a) {
98
+ switch (_a.label) {
99
+ case 0:
100
+ removeContentDirectoryPath = function (filePath) {
101
+ var pathArr = createPathArr(filePath);
102
+ var contentDirectoryPathArr = createPathArr(contentDirectoryPath);
103
+ contentDirectoryPathArr.reverse().forEach(function (dir, index) {
104
+ if (pathArr[index] === dir) {
105
+ pathArr.pop();
106
+ }
107
+ });
108
+ return '/' + pathArr.join('/');
109
+ };
110
+ removeContentDirectoryPaths = function () {
111
+ return function (tree) {
112
+ visit(tree, function (node) {
113
+ if (node == null) {
114
+ return;
115
+ }
116
+ if (node.name === 'img' || node.name === 'source') {
117
+ var srcAttrIndex = node.attributes.findIndex(function (attr) { return (attr === null || attr === void 0 ? void 0 : attr.name) === 'src'; });
118
+ var nodeUrl = node.attributes[srcAttrIndex].value;
119
+ if (
120
+ // <img/> component
121
+ srcAttrIndex !== -1 &&
122
+ !isAbsoluteUrl(nodeUrl) &&
123
+ !isDataString(nodeUrl)) {
124
+ node.attributes[srcAttrIndex].value = removeContentDirectoryPath(nodeUrl);
125
+ }
126
+ }
127
+ else if (
128
+ // ![]() format
129
+ node.type === 'image' &&
130
+ node.url &&
131
+ !isAbsoluteUrl(node.url) &&
132
+ !isDataString(node.url)) {
133
+ node.url = removeContentDirectoryPath(node.url);
134
+ }
135
+ });
136
+ return tree;
137
+ };
138
+ };
139
+ return [4 /*yield*/, remark()
140
+ .use(remarkMdx)
141
+ .use(remarkGfm)
142
+ .use(remarkFrontmatter, ['yaml', 'toml'])
143
+ .use(removeContentDirectoryPaths)
144
+ .process(fileContent)];
145
+ case 1:
146
+ file = _a.sent();
147
+ return [2 /*return*/, String(file)];
148
+ }
149
+ });
150
+ }); };
151
+ var removeLeadingSlash = function (str) {
152
+ var path = createPathArr(str);
153
+ return path.join('/');
154
+ };
155
+ var createPathArr = function (path) {
156
+ return path.split('/').filter(function (dir) { return dir !== ''; });
157
+ };
158
+ var isDataString = function (str) { return str.startsWith('data:'); };
159
+ var getOpenApiTitleAndDescription = function (openApiFiles, openApiMetaField) {
160
+ var operation = getOpenApiOperationMethodAndEndpoint(openApiFiles, openApiMetaField).operation;
161
+ if (operation == null) {
162
+ return {};
163
+ }
164
+ return {
165
+ title: operation.summary,
166
+ description: operation.description,
167
+ };
168
+ };
169
+ var getOpenApiOperationMethodAndEndpoint = function (openApiFiles, openApiMetaField) {
170
+ var _a = extractMethodAndEndpoint(openApiMetaField), endpoint = _a.endpoint, method = _a.method, filename = _a.filename;
171
+ var path;
172
+ openApiFiles === null || openApiFiles === void 0 ? void 0 : openApiFiles.forEach(function (file) {
173
+ var openApiFile = file.spec;
174
+ var openApiPath = openApiFile.paths && openApiFile.paths[endpoint];
175
+ var isFilenameOrNone = !filename || filename === file.filename;
176
+ if (openApiPath && isFilenameOrNone) {
177
+ path = openApiPath;
178
+ }
179
+ });
180
+ if (path == null) {
181
+ return {};
182
+ }
183
+ var operation;
184
+ if (method) {
185
+ operation = path[method.toLowerCase()];
186
+ }
187
+ else {
188
+ var firstOperationKey = Object.keys(path)[0];
189
+ operation = path[firstOperationKey];
190
+ }
191
+ return {
192
+ operation: operation,
193
+ method: method,
194
+ endpoint: endpoint,
195
+ };
196
+ };
197
+ var extractMethodAndEndpoint = function (openApiMetaField) {
198
+ var methodRegex = /(get|post|put|delete|patch)\s/i;
199
+ var trimmed = openApiMetaField.trim();
200
+ var foundMethod = trimmed.match(methodRegex);
201
+ var startIndexOfMethod = foundMethod ? openApiMetaField.indexOf(foundMethod[0]) : 0;
202
+ var endIndexOfMethod = foundMethod ? startIndexOfMethod + foundMethod[0].length - 1 : 0;
203
+ var filename = openApiMetaField.substring(0, startIndexOfMethod).trim();
204
+ return {
205
+ method: foundMethod ? foundMethod[0].slice(0, -1).toUpperCase() : undefined,
206
+ endpoint: openApiMetaField.substring(endIndexOfMethod).trim(),
207
+ filename: filename ? filename : undefined,
208
+ };
209
+ };
210
+ export default createPage;
@@ -1,21 +1,21 @@
1
- export declare const extractMethodAndEndpoint: (api: string) => {
2
- method?: string | undefined;
3
- endpoint: string;
4
- filename?: string | undefined;
5
- };
6
- export declare const getOpenApiOperationMethodAndEndpoint: (openApi: any, openApiMetaField: string) => {
7
- operation?: undefined;
8
- method?: undefined;
9
- endpoint?: undefined;
10
- } | {
11
- operation: any;
12
- method: string | undefined;
13
- endpoint: string;
14
- };
15
- export declare const getOpenApiTitleAndDescription: (openApi: any, openApiMetaField: any) => {
16
- title?: undefined;
17
- description?: undefined;
18
- } | {
19
- title: any;
20
- description: any;
21
- };
1
+ export declare const extractMethodAndEndpoint: (api: string) => {
2
+ method?: string | undefined;
3
+ endpoint: string;
4
+ filename?: string | undefined;
5
+ };
6
+ export declare const getOpenApiOperationMethodAndEndpoint: (openApi: any, openApiMetaField: string) => {
7
+ operation?: undefined;
8
+ method?: undefined;
9
+ endpoint?: undefined;
10
+ } | {
11
+ operation: any;
12
+ method: string | undefined;
13
+ endpoint: string;
14
+ };
15
+ export declare const getOpenApiTitleAndDescription: (openApi: any, openApiMetaField: any) => {
16
+ title?: undefined;
17
+ description?: undefined;
18
+ } | {
19
+ title: any;
20
+ description: any;
21
+ };