@mintlify/scraping 4.0.321 → 4.0.323

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mintlify/scraping",
3
- "version": "4.0.321",
3
+ "version": "4.0.323",
4
4
  "description": "Scrape documentation frameworks to Mintlify docs",
5
5
  "engines": {
6
6
  "node": ">=18.0.0"
@@ -38,7 +38,7 @@
38
38
  "format:check": "prettier . --check"
39
39
  },
40
40
  "dependencies": {
41
- "@mintlify/common": "1.0.465",
41
+ "@mintlify/common": "1.0.467",
42
42
  "@mintlify/openapi-parser": "^0.0.7",
43
43
  "fs-extra": "^11.1.1",
44
44
  "hast-util-to-mdast": "^10.1.0",
@@ -61,7 +61,7 @@
61
61
  "@mintlify/models": "0.0.214",
62
62
  "@mintlify/prettier-config": "1.0.4",
63
63
  "@mintlify/ts-config": "2.0.2",
64
- "@mintlify/validation": "0.1.426",
64
+ "@mintlify/validation": "0.1.427",
65
65
  "@trivago/prettier-plugin-sort-imports": "^4.2.1",
66
66
  "@tsconfig/recommended": "1.x",
67
67
  "@types/hast": "^3.0.4",
@@ -77,5 +77,5 @@
77
77
  "typescript": "^5.5.3",
78
78
  "vitest": "^2.0.4"
79
79
  },
80
- "gitHead": "f9f611507cf6d1bc39a70c9542e7d5276e6432b8"
80
+ "gitHead": "72ab4184ddbc325a2afeaedb9e34d4afbdf0826d"
81
81
  }
@@ -2,11 +2,13 @@ import {
2
2
  getOpenApiTitleAndDescription,
3
3
  OperationObject,
4
4
  optionallyAddLeadingSlash,
5
+ optionallyRemoveLeadingSlash,
5
6
  slugToTitle,
6
7
  isAllowedLocalSchemaUrl,
7
8
  buildOpenApiMetaTag,
8
9
  } from '@mintlify/common';
9
- import type { DecoratedNavigationPage } from '@mintlify/models';
10
+ import type { DecoratedNavigationPage, PageMetaTags } from '@mintlify/models';
11
+ import { XMint } from '@mintlify/validation';
10
12
  import { outputFile } from 'fs-extra';
11
13
  import fse from 'fs-extra';
12
14
  import fs from 'fs/promises';
@@ -20,6 +22,12 @@ import {
20
22
  } from '../apiPages/common.js';
21
23
  import { fetchOpenApi } from '../utils/network.js';
22
24
 
25
+ export type OpenApiExtensions = {
26
+ 'x-mint'?: XMint;
27
+ 'x-excluded'?: boolean;
28
+ 'x-hidden'?: boolean;
29
+ };
30
+
23
31
  export const getOpenApiDefinition = async (
24
32
  pathOrDocumentOrUrl: string | OpenAPI.Document | URL,
25
33
  localSchema?: boolean
@@ -59,17 +67,40 @@ export const createOpenApiFrontmatter = async ({
59
67
  openApiMetaTag,
60
68
  version,
61
69
  deprecated,
70
+ metadata,
71
+ extraContent,
62
72
  }: {
63
73
  filename: string;
64
74
  openApiMetaTag: string;
65
75
  version?: string;
66
76
  deprecated?: boolean;
77
+ metadata?: PageMetaTags;
78
+ extraContent?: string;
67
79
  }) => {
68
- const data = `---
69
- openapi: ${openApiMetaTag}${version ? `\nversion: ${version}` : ''}${
70
- deprecated ? `\ndeprecated: ${deprecated}` : ''
80
+ let frontmatter = `---\nopenapi: ${openApiMetaTag}`;
81
+ if (metadata && 'version' in metadata) {
82
+ frontmatter += `\nversion: ${metadata.version}`;
83
+ } else if (version) {
84
+ frontmatter += `\nversion: ${version}`;
85
+ }
86
+ if (metadata && 'deprecated' in metadata) {
87
+ frontmatter += `\ndeprecated: ${metadata.deprecated}`;
88
+ } else if (deprecated) {
89
+ frontmatter += `\ndeprecated: ${deprecated}`;
90
+ }
91
+
92
+ if (metadata) {
93
+ const reserved = new Set(['openapi', 'version', 'deprecated']);
94
+ Object.entries(metadata)
95
+ .filter(([k]) => !reserved.has(k))
96
+ .forEach(([key, value]) => {
97
+ frontmatter += `\n${key}: ${value}`;
98
+ });
71
99
  }
72
- ---`;
100
+
101
+ frontmatter += `\n---`;
102
+
103
+ const data = extraContent ? `${frontmatter}\n\n${extraContent}` : frontmatter;
73
104
 
74
105
  await outputFile(filename, data);
75
106
  };
@@ -107,7 +138,7 @@ const isExcludedOperation = (operation: MaybeOperationObjectWithExtensions) => {
107
138
 
108
139
  export function processOpenApiPath<N, DN>(
109
140
  path: string,
110
- pathItemObject: OpenAPIV3.PathItemObject,
141
+ pathItemObject: OpenAPIV3.PathItemObject<OpenApiExtensions>,
111
142
  schema: OpenAPI.Document,
112
143
  nav: N,
113
144
  decoratedNav: DN,
@@ -127,17 +158,32 @@ export function processOpenApiPath<N, DN>(
127
158
  if (isExcludedOperation(operation as MaybeOperationObjectWithExtensions)) {
128
159
  return;
129
160
  }
161
+ const xMint = operation?.['x-mint'];
162
+
163
+ if (xMint?.href) {
164
+ xMint.href = optionallyAddLeadingSlash(xMint.href);
165
+ }
166
+
130
167
  const groupName = operation?.tags?.[0];
131
- const title =
168
+ let title =
132
169
  prepareStringToBeValidFilename(operation?.summary) ??
133
170
  `${method}-${prepareStringToBeValidFilename(path)}`;
134
- const folder = prepareStringToBeValidFilename(groupName) ?? '';
135
- const base = join(options.outDir ?? '', folder, title);
171
+
172
+ let folder = prepareStringToBeValidFilename(groupName) ?? '';
173
+ let base = join(options.outDir ?? '', folder, title);
174
+
175
+ if (xMint?.href) {
176
+ const slug = optionallyRemoveLeadingSlash(xMint.href);
177
+ title = parse(slug).name;
178
+ folder = parse(slug).dir;
179
+ base = join(folder, title);
180
+ }
136
181
 
137
182
  const navGroup = findNavGroup(nav, groupName);
138
183
  const decoratedNavGroup = findNavGroup(decoratedNav, groupName);
139
184
 
140
185
  const filenameWithoutExtension = generateUniqueFilenameWithoutExtension(navGroup, base);
186
+
141
187
  const openapiMetaTag = buildOpenApiMetaTag({
142
188
  filePath: openApiFilePathFromRoot,
143
189
  method,
@@ -158,8 +204,8 @@ export function processOpenApiPath<N, DN>(
158
204
  const page: DecoratedNavigationPage = {
159
205
  openapi: openapiMetaTag,
160
206
  href: resolve('/', filenameWithoutExtension),
161
- title: titleTag ?? slugToTitle(filenameWithoutExtension),
162
- description,
207
+ title: xMint?.metadata?.title ?? titleTag ?? slugToTitle(filenameWithoutExtension),
208
+ description: xMint?.metadata?.description ?? description,
163
209
  deprecated: operation?.deprecated,
164
210
  version: options.version,
165
211
  };
@@ -169,6 +215,7 @@ export function processOpenApiPath<N, DN>(
169
215
  decoratedNavGroup.push(page);
170
216
  }
171
217
  pagesAcc[filenameWithoutExtension] = page;
218
+
172
219
  const targetPath = options.outDirBasePath
173
220
  ? join(options.outDirBasePath, `${filenameWithoutExtension}.mdx`)
174
221
  : `${filenameWithoutExtension}.mdx`;
@@ -179,6 +226,8 @@ export function processOpenApiPath<N, DN>(
179
226
  openApiMetaTag: openapiMetaTag,
180
227
  version: options.version,
181
228
  deprecated: operation?.deprecated,
229
+ metadata: xMint?.metadata,
230
+ extraContent: xMint?.content,
182
231
  })
183
232
  );
184
233
  }
@@ -188,7 +237,7 @@ export function processOpenApiPath<N, DN>(
188
237
 
189
238
  export function processOpenApiWebhook<N, DN>(
190
239
  webhook: string,
191
- webhookObject: OpenAPIV3.PathItemObject,
240
+ webhookObject: OpenAPIV3.PathItemObject<OpenApiExtensions>,
192
241
  _schema: OpenAPI.Document,
193
242
  nav: N,
194
243
  decoratedNav: DN,
@@ -208,12 +257,25 @@ export function processOpenApiWebhook<N, DN>(
208
257
  if (isExcludedOperation(operation as MaybeOperationObjectWithExtensions)) {
209
258
  return;
210
259
  }
260
+ const xMint = operation?.['x-mint'];
261
+
262
+ if (xMint?.href) {
263
+ xMint.href = optionallyAddLeadingSlash(xMint.href);
264
+ }
265
+
211
266
  const groupName = operation?.tags?.[0];
212
- const title =
267
+ let title =
213
268
  prepareStringToBeValidFilename(operation?.summary) ??
214
269
  `${prepareStringToBeValidFilename(webhook)}`;
215
- const folder = prepareStringToBeValidFilename(groupName) ?? '';
216
- const base = join(options.outDir ?? '', folder, title);
270
+ let folder = prepareStringToBeValidFilename(groupName) ?? '';
271
+ let base = join(options.outDir ?? '', folder, title);
272
+
273
+ if (xMint?.href) {
274
+ const slug = optionallyRemoveLeadingSlash(xMint.href);
275
+ title = parse(slug).name;
276
+ folder = parse(slug).dir;
277
+ base = join(folder, title);
278
+ }
217
279
 
218
280
  const navGroup = findNavGroup(nav, groupName);
219
281
  const decoratedNavGroup = findNavGroup(decoratedNav, groupName);
@@ -226,12 +288,12 @@ export function processOpenApiWebhook<N, DN>(
226
288
  path: webhook,
227
289
  });
228
290
 
229
- const description = operation?.description;
291
+ const description = xMint?.metadata?.description ?? operation?.description;
230
292
 
231
293
  const page: DecoratedNavigationPage = {
232
294
  openapi: openapiMetaTag,
233
295
  href: resolve('/', filenameWithoutExtension),
234
- title: slugToTitle(filenameWithoutExtension),
296
+ title: xMint?.metadata?.title ?? slugToTitle(filenameWithoutExtension),
235
297
  description,
236
298
  version: options.version,
237
299
  deprecated: operation?.deprecated,
@@ -252,6 +314,8 @@ export function processOpenApiWebhook<N, DN>(
252
314
  openApiMetaTag: openapiMetaTag,
253
315
  version: options.version,
254
316
  deprecated: operation?.deprecated,
317
+ metadata: xMint?.metadata,
318
+ extraContent: xMint?.content,
255
319
  })
256
320
  );
257
321
  }