@mintlify/common 1.0.622 → 1.0.624

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.
@@ -0,0 +1,3 @@
1
+ export { parseFrontmatter, hasFrontmatter } from './parseFrontmatter.js';
2
+ export type { FrontmatterAttributes } from './parseFrontmatter.js';
3
+ export type { FrontMatterResult } from 'front-matter';
@@ -0,0 +1 @@
1
+ export { parseFrontmatter, hasFrontmatter } from './parseFrontmatter.js';
@@ -0,0 +1,34 @@
1
+ import type { FrontMatterResult } from 'front-matter';
2
+ /**
3
+ * Default type for frontmatter attributes when no specific type is provided.
4
+ * Represents a flexible object that can contain any valid JSON-like values.
5
+ */
6
+ export type FrontmatterAttributes = Record<string, string | undefined>;
7
+ /**
8
+ * Type-safe wrapper for parsing front-matter from markdown content.
9
+ *
10
+ * @template T - The expected type of the frontmatter attributes
11
+ * @param content - The markdown content string to parse
12
+ * @returns A FrontMatterResult with properly typed attributes
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * interface MyFrontmatter {
17
+ * title: string;
18
+ * description?: string;
19
+ * tags?: string[];
20
+ * }
21
+ *
22
+ * const result = parseFrontmatter<MyFrontmatter>(content);
23
+ * // result.attributes is now typed as MyFrontmatter
24
+ * console.log(result.attributes.title);
25
+ * ```
26
+ */
27
+ export declare function parseFrontmatter<T = FrontmatterAttributes>(content: string): FrontMatterResult<T>;
28
+ /**
29
+ * Tests whether a string contains frontmatter
30
+ *
31
+ * @param content - The content to test
32
+ * @returns true if the content contains frontmatter
33
+ */
34
+ export declare function hasFrontmatter(content: string): boolean;
@@ -0,0 +1,35 @@
1
+ import fm from 'front-matter';
2
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
3
+ const frontmatter = fm;
4
+ /**
5
+ * Type-safe wrapper for parsing front-matter from markdown content.
6
+ *
7
+ * @template T - The expected type of the frontmatter attributes
8
+ * @param content - The markdown content string to parse
9
+ * @returns A FrontMatterResult with properly typed attributes
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * interface MyFrontmatter {
14
+ * title: string;
15
+ * description?: string;
16
+ * tags?: string[];
17
+ * }
18
+ *
19
+ * const result = parseFrontmatter<MyFrontmatter>(content);
20
+ * // result.attributes is now typed as MyFrontmatter
21
+ * console.log(result.attributes.title);
22
+ * ```
23
+ */
24
+ export function parseFrontmatter(content) {
25
+ return frontmatter(content);
26
+ }
27
+ /**
28
+ * Tests whether a string contains frontmatter
29
+ *
30
+ * @param content - The content to test
31
+ * @returns true if the content contains frontmatter
32
+ */
33
+ export function hasFrontmatter(content) {
34
+ return frontmatter.test(content);
35
+ }
package/dist/index.d.ts CHANGED
@@ -5,6 +5,7 @@ export * from './mdx/index.js';
5
5
  export * from './getFileCategory.js';
6
6
  export * from './slug/index.js';
7
7
  export * from './fs/index.js';
8
+ export * from './frontmatter/index.js';
8
9
  export * from './getSecurityOptionsForAuthMethod.js';
9
10
  export * from './getFileCategory.js';
10
11
  export * from './topologicalSort.js';
package/dist/index.js CHANGED
@@ -5,6 +5,7 @@ export * from './mdx/index.js';
5
5
  export * from './getFileCategory.js';
6
6
  export * from './slug/index.js';
7
7
  export * from './fs/index.js';
8
+ export * from './frontmatter/index.js';
8
9
  export * from './getSecurityOptionsForAuthMethod.js';
9
10
  export * from './getFileCategory.js';
10
11
  export * from './topologicalSort.js';
@@ -14,6 +14,7 @@ export const remarkExtractTableOfContents = (mdxExtracts, pageMetadata) => {
14
14
  let hasTopLayer = false;
15
15
  // the key is the node in unist
16
16
  const tabContentMap = new Map();
17
+ const viewContentMap = new Map();
17
18
  const excludedNodes = new Set();
18
19
  visit(tree, (node) => {
19
20
  if (node.type === 'mdxJsxFlowElement' &&
@@ -40,12 +41,25 @@ export const remarkExtractTableOfContents = (mdxExtracts, pageMetadata) => {
40
41
  });
41
42
  }
42
43
  }
44
+ if (node.type === 'mdxJsxFlowElement' && node.name === 'View') {
45
+ const titleAttr = node.attributes.find((attr) => 'name' in attr && attr.name === 'title');
46
+ let viewId;
47
+ if (titleAttr && 'value' in titleAttr && typeof titleAttr.value === 'string') {
48
+ viewId = titleAttr.value;
49
+ }
50
+ if (viewId) {
51
+ visit(node, (childNode) => {
52
+ viewContentMap.set(childNode, viewId);
53
+ });
54
+ }
55
+ }
43
56
  });
44
57
  visit(tree, (node) => {
45
58
  var _a, _b, _c, _d, _e;
46
59
  if (excludedNodes.has(node))
47
60
  return;
48
61
  const currentTabId = tabContentMap.get(node);
62
+ const currentViewId = viewContentMap.get(node);
49
63
  const isValidHeading = node.type === 'heading' && HEADING_LEVELS.includes(node.depth);
50
64
  const isValidMdxHeading = node.type === 'mdxJsxFlowElement' && HEADING_NAMES.includes((_a = node.name) !== null && _a !== void 0 ? _a : '');
51
65
  const isTransformedHeading = node.type === 'mdxJsxFlowElement' && node.name === 'Heading';
@@ -118,7 +132,14 @@ export const remarkExtractTableOfContents = (mdxExtracts, pageMetadata) => {
118
132
  const depth = node.depth;
119
133
  if (level !== undefined && Number(level) <= 2) {
120
134
  hasTopLayer = true;
121
- contents.push({ title, slug, depth, children: [], tabId: currentTabId });
135
+ contents.push({
136
+ title,
137
+ slug,
138
+ depth,
139
+ children: [],
140
+ tabId: currentTabId,
141
+ viewId: currentViewId,
142
+ });
122
143
  }
123
144
  else {
124
145
  // Account if there is no first layer
@@ -126,7 +147,14 @@ export const remarkExtractTableOfContents = (mdxExtracts, pageMetadata) => {
126
147
  if (hasTopLayer) {
127
148
  arrToPushInto = (_e = (_d = contents.at(-1)) === null || _d === void 0 ? void 0 : _d.children) !== null && _e !== void 0 ? _e : [];
128
149
  }
129
- arrToPushInto.push({ title, slug, depth, children: [], tabId: currentTabId });
150
+ arrToPushInto.push({
151
+ title,
152
+ slug,
153
+ depth,
154
+ children: [],
155
+ tabId: currentTabId,
156
+ viewId: currentViewId,
157
+ });
130
158
  }
131
159
  });
132
160
  if (mdxExtracts) {
@@ -1,8 +1,4 @@
1
1
  import type { Root, RootContent } from 'mdast';
2
- /**
3
- * Injects content to the top of a file, but below the frontmatter
4
- */
5
- export declare const injectToTopOfFile: (content: string, contentToInject: string) => string;
6
2
  /**
7
3
  * Injects nodes to the top of a MDX/Markdown AST (Root), but below the frontmatter (YAML node).
8
4
  * Modifies the tree in place.
@@ -1,14 +1,3 @@
1
- import matter from 'gray-matter';
2
- const { test: hasFrontmatter } = matter;
3
- /**
4
- * Injects content to the top of a file, but below the frontmatter
5
- */
6
- export const injectToTopOfFile = (content, contentToInject) => {
7
- if (!hasFrontmatter(content))
8
- return contentToInject + `\n` + content;
9
- const { data: frontmatterData, content: contentWithoutFrontmatter } = matter(content);
10
- return matter.stringify(`\n` + contentToInject + `\n` + contentWithoutFrontmatter, frontmatterData);
11
- };
12
1
  /**
13
2
  * Injects nodes to the top of a MDX/Markdown AST (Root), but below the frontmatter (YAML node).
14
3
  * Modifies the tree in place.
@@ -1,6 +1,6 @@
1
- import matter from 'gray-matter';
2
1
  import { getAsyncApiChannelMetadata } from '../asyncapi/getAsyncApiChannelMetadata.js';
3
2
  import { prepAsyncApiFrontmatter } from '../asyncapi/prepAsyncApiFrontmatter.js';
3
+ import { parseFrontmatter } from '../frontmatter/index.js';
4
4
  import { removeLeadingSlash, optionallyAddLeadingSlash } from '../fs/index.js';
5
5
  import { getOpenApiTitleAndDescription } from '../openapi/getOpenApiTitleAndDescription.js';
6
6
  import { prepOpenApiFrontmatter } from '../openapi/prepOpenApiFrontmatter.js';
@@ -9,7 +9,7 @@ import { slugToTitle } from './slugToTitle.js';
9
9
  export const getDecoratedNavPageAndSlug = (pagePath, pageContent, openApiFiles, asyncApiFiles) => {
10
10
  let metadata = {};
11
11
  try {
12
- metadata = matter(pageContent).data;
12
+ metadata = parseFrontmatter(pageContent).attributes;
13
13
  }
14
14
  catch (error) {
15
15
  if (error &&