@mintlify/common 1.0.322 → 1.0.324
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/dist/asyncapi/getAsyncApiChannelMetadata.d.ts +2 -0
- package/dist/asyncapi/getAsyncApiChannelMetadata.js +30 -0
- package/dist/asyncapi/parseAsyncApiString.d.ts +2 -0
- package/dist/asyncapi/parseAsyncApiString.js +21 -0
- package/dist/asyncapi/prepAsyncApiFrontmatter.d.ts +1 -0
- package/dist/asyncapi/prepAsyncApiFrontmatter.js +18 -0
- package/dist/camelToSentenceCase.d.ts +1 -0
- package/dist/camelToSentenceCase.js +8 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/mdx/plugins/remark/index.d.ts +3 -0
- package/dist/mdx/plugins/remark/index.js +3 -0
- package/dist/mdx/plugins/remark/remarkExpandContent.d.ts +2 -0
- package/dist/mdx/plugins/remark/remarkExpandContent.js +21 -0
- package/dist/mdx/plugins/remark/remarkSplitCodeGroup.d.ts +2 -0
- package/dist/mdx/plugins/remark/remarkSplitCodeGroup.js +19 -0
- package/dist/mdx/plugins/remark/remarkSplitTabs.d.ts +2 -0
- package/dist/mdx/plugins/remark/remarkSplitTabs.js +56 -0
- package/dist/openapi/index.d.ts +0 -1
- package/dist/openapi/index.js +0 -1
- package/dist/openapi/prepOpenApiFrontmatter.js +3 -3
- package/dist/schema/common.d.ts +1 -0
- package/dist/schema/common.js +6 -0
- package/dist/slug/getDecoratedNavPageAndSlug.d.ts +2 -1
- package/dist/slug/getDecoratedNavPageAndSlug.js +15 -8
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/asyncapi.d.ts +6 -0
- package/package.json +2 -2
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { parseAsyncApiString } from './parseAsyncApiString.js';
|
|
2
|
+
export const getAsyncApiChannelMetadata = (asyncApiMetaField, asyncApiFiles) => {
|
|
3
|
+
var _a, _b;
|
|
4
|
+
const potentiallyParsedAsyncApiString = parseAsyncApiString(asyncApiMetaField);
|
|
5
|
+
if (potentiallyParsedAsyncApiString == undefined) {
|
|
6
|
+
return undefined;
|
|
7
|
+
}
|
|
8
|
+
const { channelId, filename } = potentiallyParsedAsyncApiString;
|
|
9
|
+
let asyncApiFile = undefined;
|
|
10
|
+
for (const file of asyncApiFiles) {
|
|
11
|
+
const asyncApiSpec = file.spec;
|
|
12
|
+
const hasAsyncApiChannel = asyncApiSpec.allChannels().has(channelId);
|
|
13
|
+
const filenameMatches = !filename || filename === file.filename || filename === file.originalFileLocation;
|
|
14
|
+
if (hasAsyncApiChannel && filenameMatches) {
|
|
15
|
+
asyncApiFile = file;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
if (asyncApiFile == null) {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
const channelInterface = asyncApiFile.spec.channels().get(channelId);
|
|
22
|
+
const channelTitle = (_a = channelInterface.title()) !== null && _a !== void 0 ? _a : '';
|
|
23
|
+
const channelDescription = (_b = channelInterface.description()) !== null && _b !== void 0 ? _b : '';
|
|
24
|
+
return {
|
|
25
|
+
channelId,
|
|
26
|
+
filename: asyncApiFile.filename,
|
|
27
|
+
title: channelTitle,
|
|
28
|
+
description: channelDescription,
|
|
29
|
+
};
|
|
30
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export const parseAsyncApiString = (str) => {
|
|
2
|
+
const components = str.trim().split(/\s+/);
|
|
3
|
+
let filename;
|
|
4
|
+
let channelId;
|
|
5
|
+
if (components.length > 2) {
|
|
6
|
+
return undefined;
|
|
7
|
+
}
|
|
8
|
+
else if (components[0] && components[1]) {
|
|
9
|
+
[filename, channelId] = components;
|
|
10
|
+
}
|
|
11
|
+
else if (components[0]) {
|
|
12
|
+
channelId = components[0];
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
filename,
|
|
19
|
+
channelId,
|
|
20
|
+
};
|
|
21
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function prepAsyncApiFrontmatter(currPath: string, asyncApiFrontmatter?: string): string | undefined;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { parse } from 'path';
|
|
2
|
+
import { parseAsyncApiString } from '../asyncapi/parseAsyncApiString.js';
|
|
3
|
+
import { normalizeRelativePath } from '../fs/normalizeRelativePath.js';
|
|
4
|
+
import { schemaFileFrontmatterIsOriginalFileLocation } from '../schema/common.js';
|
|
5
|
+
export function prepAsyncApiFrontmatter(currPath, asyncApiFrontmatter) {
|
|
6
|
+
if (!asyncApiFrontmatter)
|
|
7
|
+
return undefined;
|
|
8
|
+
const asyncApiObj = parseAsyncApiString(asyncApiFrontmatter);
|
|
9
|
+
if ((asyncApiObj === null || asyncApiObj === void 0 ? void 0 : asyncApiObj.filename) && schemaFileFrontmatterIsOriginalFileLocation(asyncApiObj.filename)) {
|
|
10
|
+
if (asyncApiObj.filename.startsWith('https://')) {
|
|
11
|
+
return `${asyncApiObj.filename} ${asyncApiObj.channelId}`;
|
|
12
|
+
}
|
|
13
|
+
const currDir = parse(currPath).dir;
|
|
14
|
+
const newAsyncApiFilename = normalizeRelativePath(currDir, asyncApiObj.filename);
|
|
15
|
+
return `${newAsyncApiFilename} ${asyncApiObj.channelId}`;
|
|
16
|
+
}
|
|
17
|
+
return asyncApiFrontmatter;
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const camelToSentenceCase: (str: string) => string;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export const camelToSentenceCase = (str) => {
|
|
2
|
+
// Split on capital letters and convert to lowercase
|
|
3
|
+
const words = str.split(/(?=[A-Z])/).map((word) => word.toLowerCase());
|
|
4
|
+
// Capitalize first word and join with spaces
|
|
5
|
+
return words
|
|
6
|
+
.map((word, index) => (index === 0 ? word.charAt(0).toUpperCase() + word.slice(1) : word))
|
|
7
|
+
.join(' ');
|
|
8
|
+
};
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -8,3 +8,6 @@ export * from './remarkReplaceAllImages.js';
|
|
|
8
8
|
export * from './remarkMermaid.js';
|
|
9
9
|
export * from './remarkMdxRemoveJs.js';
|
|
10
10
|
export * from './remarkExtractChangelogFilters.js';
|
|
11
|
+
export * from './remarkExpandContent.js';
|
|
12
|
+
export * from './remarkSplitCodeGroup.js';
|
|
13
|
+
export * from './remarkSplitTabs.js';
|
|
@@ -8,3 +8,6 @@ export * from './remarkReplaceAllImages.js';
|
|
|
8
8
|
export * from './remarkMermaid.js';
|
|
9
9
|
export * from './remarkMdxRemoveJs.js';
|
|
10
10
|
export * from './remarkExtractChangelogFilters.js';
|
|
11
|
+
export * from './remarkExpandContent.js';
|
|
12
|
+
export * from './remarkSplitCodeGroup.js';
|
|
13
|
+
export * from './remarkSplitTabs.js';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { visit } from 'unist-util-visit';
|
|
2
|
+
export const remarkExpandContent = () => (tree) => {
|
|
3
|
+
visit(tree, 'mdxJsxFlowElement', (node) => {
|
|
4
|
+
if (node.name === 'Accordion' || node.name === 'Expandable') {
|
|
5
|
+
const defaultOpenAttr = node.attributes.find(isDefaultOpenAttr);
|
|
6
|
+
if (defaultOpenAttr) {
|
|
7
|
+
defaultOpenAttr.value = 'true';
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
node.attributes.push({
|
|
11
|
+
type: 'mdxJsxAttribute',
|
|
12
|
+
name: 'defaultOpen',
|
|
13
|
+
value: 'true',
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
const isDefaultOpenAttr = (attr) => {
|
|
20
|
+
return attr.type === 'mdxJsxAttribute' && attr.name === 'defaultOpen';
|
|
21
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { visit } from 'unist-util-visit';
|
|
2
|
+
export const remarkSplitCodeGroup = () => (tree) => {
|
|
3
|
+
const codeGroupCompoenents = ['CodeGroup', 'RequestExample', 'ResponseExample'];
|
|
4
|
+
const groupsToProcess = [];
|
|
5
|
+
visit(tree, 'mdxJsxFlowElement', (node, index, parent) => {
|
|
6
|
+
if (node.name && codeGroupCompoenents.includes(node.name) && index && parent) {
|
|
7
|
+
groupsToProcess.push({ node, index, parent });
|
|
8
|
+
}
|
|
9
|
+
});
|
|
10
|
+
// Split the code group into multiple CodeBlock nodes
|
|
11
|
+
// basically remove the CodeGroup component and replace it with the codeblocks
|
|
12
|
+
for (const { node, index, parent } of groupsToProcess) {
|
|
13
|
+
const numberOfCodeBlocks = node.children.length;
|
|
14
|
+
if (numberOfCodeBlocks <= 1)
|
|
15
|
+
continue;
|
|
16
|
+
const newNodes = node.children;
|
|
17
|
+
parent.children.splice(index, 1, ...newNodes);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { visit } from 'unist-util-visit';
|
|
2
|
+
export const remarkSplitTabs = () => (tree) => {
|
|
3
|
+
const tabsToProcess = [];
|
|
4
|
+
visit(tree, 'mdxJsxFlowElement', (node, index, parent) => {
|
|
5
|
+
if (node.name === 'Tabs' && index && parent) {
|
|
6
|
+
tabsToProcess.push({ node, index, parent });
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
for (const { node, index, parent } of tabsToProcess) {
|
|
10
|
+
const numberOfTabs = node.children.length;
|
|
11
|
+
if (numberOfTabs <= 1)
|
|
12
|
+
continue;
|
|
13
|
+
const newNodes = [];
|
|
14
|
+
for (let i = 0; i < numberOfTabs; i++) {
|
|
15
|
+
const newNode = structuredClone(node);
|
|
16
|
+
const defaultTabIndexAttr = newNode.attributes.find(isDefaultTabIndexAttr);
|
|
17
|
+
if (defaultTabIndexAttr) {
|
|
18
|
+
defaultTabIndexAttr.value = formValueExpression(i);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
newNode.attributes.push({
|
|
22
|
+
type: 'mdxJsxAttribute',
|
|
23
|
+
name: 'defaultTabIndex',
|
|
24
|
+
value: formValueExpression(i),
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
newNodes.push(newNode);
|
|
28
|
+
}
|
|
29
|
+
parent.children.splice(index, 1, ...newNodes);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
const isDefaultTabIndexAttr = (attr) => {
|
|
33
|
+
return attr.type === 'mdxJsxAttribute' && attr.name === 'defaultTabIndex';
|
|
34
|
+
};
|
|
35
|
+
const formValueExpression = (value) => {
|
|
36
|
+
return {
|
|
37
|
+
type: 'mdxJsxAttributeValueExpression',
|
|
38
|
+
value: value.toString(),
|
|
39
|
+
data: {
|
|
40
|
+
estree: {
|
|
41
|
+
type: 'Program',
|
|
42
|
+
body: [
|
|
43
|
+
{
|
|
44
|
+
type: 'ExpressionStatement',
|
|
45
|
+
expression: {
|
|
46
|
+
type: 'Literal',
|
|
47
|
+
value: value,
|
|
48
|
+
raw: value.toString(),
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
sourceType: 'module',
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
};
|
package/dist/openapi/index.d.ts
CHANGED
|
@@ -6,4 +6,3 @@ export { getOpenApiTitleAndDescription } from './getOpenApiTitleAndDescription.j
|
|
|
6
6
|
export { validate, safeValidate } from './validate.js';
|
|
7
7
|
export { getOpenApiDocumentFromUrl } from './getOpenApiDocumentFromUrl.js';
|
|
8
8
|
export { prepOpenApiFrontmatter } from './prepOpenApiFrontmatter.js';
|
|
9
|
-
export { openApiFrontmatterIsOriginalFileLocation } from './openApiFrontmatterIsOriginalFileLocation.js';
|
package/dist/openapi/index.js
CHANGED
|
@@ -6,4 +6,3 @@ export { getOpenApiTitleAndDescription } from './getOpenApiTitleAndDescription.j
|
|
|
6
6
|
export { validate, safeValidate } from './validate.js';
|
|
7
7
|
export { getOpenApiDocumentFromUrl } from './getOpenApiDocumentFromUrl.js';
|
|
8
8
|
export { prepOpenApiFrontmatter } from './prepOpenApiFrontmatter.js';
|
|
9
|
-
export { openApiFrontmatterIsOriginalFileLocation } from './openApiFrontmatterIsOriginalFileLocation.js';
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { parse, isAbsolute } from 'path';
|
|
2
2
|
import { normalizeRelativePath } from '../fs/normalizeRelativePath.js';
|
|
3
|
-
import {
|
|
3
|
+
import { schemaFileFrontmatterIsOriginalFileLocation } from '../schema/common.js';
|
|
4
4
|
import { potentiallyParseOpenApiString } from './parseOpenApiString.js';
|
|
5
5
|
export function prepOpenApiFrontmatter(currPath, openapiFrontmatter) {
|
|
6
6
|
if (!openapiFrontmatter)
|
|
7
7
|
return undefined;
|
|
8
8
|
const openapiObj = potentiallyParseOpenApiString(openapiFrontmatter);
|
|
9
|
-
if ((openapiObj === null || openapiObj === void 0 ? void 0 : openapiObj.filename) &&
|
|
10
|
-
if (openapiObj.filename.startsWith('
|
|
9
|
+
if ((openapiObj === null || openapiObj === void 0 ? void 0 : openapiObj.filename) && schemaFileFrontmatterIsOriginalFileLocation(openapiObj.filename)) {
|
|
10
|
+
if (openapiObj.filename.startsWith('https://')) {
|
|
11
11
|
return `${openapiObj.filename} ${openapiObj.method.toLowerCase()} ${openapiObj.endpoint}`;
|
|
12
12
|
}
|
|
13
13
|
const filenameIsAbsolute = isAbsolute(openapiObj.filename);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const schemaFileFrontmatterIsOriginalFileLocation: (filenameFromFrontmatter: string) => boolean;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// Functions used for both OpenAPI and AsyncAPI schemas
|
|
2
|
+
export const schemaFileFrontmatterIsOriginalFileLocation = (filenameFromFrontmatter) => {
|
|
3
|
+
return (filenameFromFrontmatter.toLowerCase().endsWith('.json') ||
|
|
4
|
+
filenameFromFrontmatter.toLowerCase().endsWith('.yaml') ||
|
|
5
|
+
filenameFromFrontmatter.toLowerCase().endsWith('.yml'));
|
|
6
|
+
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { OpenApiFile, DecoratedNavigationPage } from '@mintlify/models';
|
|
2
|
-
|
|
2
|
+
import { AsyncAPIFile } from '../types/asyncapi.js';
|
|
3
|
+
export declare const getDecoratedNavPageAndSlug: (pagePath: string, pageContent: string, openApiFiles: OpenApiFile[], asyncApiFiles: AsyncAPIFile[]) => {
|
|
3
4
|
pageMetadata: DecoratedNavigationPage;
|
|
4
5
|
slug: string;
|
|
5
6
|
};
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import matter from 'gray-matter';
|
|
2
|
+
import { getAsyncApiChannelMetadata } from '../asyncapi/getAsyncApiChannelMetadata.js';
|
|
3
|
+
import { prepAsyncApiFrontmatter } from '../asyncapi/prepAsyncApiFrontmatter.js';
|
|
2
4
|
import { removeLeadingSlash, optionallyAddLeadingSlash } from '../fs/index.js';
|
|
3
5
|
import { getOpenApiTitleAndDescription } from '../openapi/getOpenApiTitleAndDescription.js';
|
|
4
6
|
import { prepOpenApiFrontmatter } from '../openapi/prepOpenApiFrontmatter.js';
|
|
5
7
|
import { pagePathToSlug } from './pagePathToSlug.js';
|
|
6
8
|
import { slugToTitle } from './slugToTitle.js';
|
|
7
|
-
export const getDecoratedNavPageAndSlug = (pagePath, pageContent, openApiFiles) => {
|
|
9
|
+
export const getDecoratedNavPageAndSlug = (pagePath, pageContent, openApiFiles, asyncApiFiles) => {
|
|
8
10
|
let metadata = {};
|
|
9
11
|
try {
|
|
10
12
|
metadata = matter(pageContent).data;
|
|
@@ -26,16 +28,21 @@ export const getDecoratedNavPageAndSlug = (pagePath, pageContent, openApiFiles)
|
|
|
26
28
|
}
|
|
27
29
|
const slug = pagePathToSlug(pagePath);
|
|
28
30
|
const defaultTitle = slugToTitle(slug);
|
|
29
|
-
|
|
30
|
-
let
|
|
31
|
-
let openApiDescription;
|
|
31
|
+
let schemaTitle;
|
|
32
|
+
let schemaDescription;
|
|
32
33
|
if (metadata.openapi) {
|
|
33
34
|
metadata.openapi = prepOpenApiFrontmatter(pagePath, metadata.openapi);
|
|
34
|
-
const { title, description } = getOpenApiTitleAndDescription(openApiFiles, metadata.openapi);
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
const { title: openApiSchemaTitle, description: openApiSchemaDescription } = getOpenApiTitleAndDescription(openApiFiles, metadata.openapi);
|
|
36
|
+
schemaTitle = openApiSchemaTitle;
|
|
37
|
+
schemaDescription = openApiSchemaDescription;
|
|
37
38
|
}
|
|
38
|
-
|
|
39
|
+
if (metadata.asyncapi) {
|
|
40
|
+
metadata.asyncapi = prepAsyncApiFrontmatter(pagePath, metadata.asyncapi);
|
|
41
|
+
const parsedMetadata = getAsyncApiChannelMetadata(metadata.asyncapi, asyncApiFiles);
|
|
42
|
+
schemaTitle = parsedMetadata === null || parsedMetadata === void 0 ? void 0 : parsedMetadata.title;
|
|
43
|
+
schemaDescription = parsedMetadata === null || parsedMetadata === void 0 ? void 0 : parsedMetadata.description;
|
|
44
|
+
}
|
|
45
|
+
const pageMetadata = Object.assign(Object.assign({ title: schemaTitle !== null && schemaTitle !== void 0 ? schemaTitle : defaultTitle, description: schemaDescription }, metadata), { href: optionallyAddLeadingSlash(slug) });
|
|
39
46
|
return {
|
|
40
47
|
pageMetadata,
|
|
41
48
|
slug: removeLeadingSlash(slug),
|