@mintlify/prebuild 1.0.1441 → 1.0.1442

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,21 @@
1
+ type NavGroup = {
2
+ group: string;
3
+ pages: (string | NavGroup)[];
4
+ };
5
+ export type GeneratedDocsConfig = {
6
+ $schema: string;
7
+ theme: 'mint';
8
+ name: string;
9
+ colors: {
10
+ primary: string;
11
+ };
12
+ navigation: {
13
+ groups: NavGroup[];
14
+ };
15
+ };
16
+ /**
17
+ * Builds a minimal docs.json for a folder of Markdown files with no config: root pages form
18
+ * the first group and each top-level folder becomes a group, with nested folders as subgroups.
19
+ */
20
+ export declare const generateDocsConfig: (filePaths: string[], name: string) => GeneratedDocsConfig;
21
+ export {};
@@ -0,0 +1,59 @@
1
+ import { slugToTitle } from '@mintlify/common';
2
+ import pathUtil from 'path';
3
+ const PAGE_EXTENSION = /\.mdx?$/i;
4
+ const EXCLUDED_SEGMENTS = new Set(['node_modules', 'snippets']);
5
+ const LEADING_PAGES = ['index', 'readme'];
6
+ const isContentPage = (filePath) => PAGE_EXTENSION.test(filePath) &&
7
+ filePath
8
+ .split('/')
9
+ .every((segment) => !segment.startsWith('.') && !segment.startsWith('_') && !EXCLUDED_SEGMENTS.has(segment));
10
+ const compareNames = (a, b) => {
11
+ const rank = (name) => {
12
+ const index = LEADING_PAGES.indexOf(pathUtil.posix.basename(name).toLowerCase());
13
+ return index === -1 ? LEADING_PAGES.length : index;
14
+ };
15
+ return rank(a) - rank(b) || a.localeCompare(b, undefined, { numeric: true, sensitivity: 'base' });
16
+ };
17
+ const folderTitle = (folder) => slugToTitle(folder.replace(/^\d+[-_.\s]+/, ''));
18
+ const toPages = (node) => [
19
+ ...[...node.pages].sort(compareNames),
20
+ ...[...node.folders.entries()]
21
+ .sort(([a], [b]) => compareNames(a, b))
22
+ .map(([name, child]) => ({ group: folderTitle(name), pages: toPages(child) })),
23
+ ];
24
+ /**
25
+ * Builds a minimal docs.json for a folder of Markdown files with no config: root pages form
26
+ * the first group and each top-level folder becomes a group, with nested folders as subgroups.
27
+ */
28
+ export const generateDocsConfig = (filePaths, name) => {
29
+ const root = { pages: [], folders: new Map() };
30
+ for (const filePath of filePaths.map((path) => path.replaceAll('\\', '/'))) {
31
+ if (!isContentPage(filePath))
32
+ continue;
33
+ const segments = filePath.replace(PAGE_EXTENSION, '').split('/');
34
+ const page = segments.join('/');
35
+ let node = root;
36
+ for (const segment of segments.slice(0, -1)) {
37
+ let child = node.folders.get(segment);
38
+ if (!child) {
39
+ child = { pages: [], folders: new Map() };
40
+ node.folders.set(segment, child);
41
+ }
42
+ node = child;
43
+ }
44
+ node.pages.push(page);
45
+ }
46
+ const groups = [];
47
+ if (root.pages.length)
48
+ groups.push({ group: 'Introduction', pages: [...root.pages].sort(compareNames) });
49
+ for (const [folder, child] of [...root.folders.entries()].sort(([a], [b]) => compareNames(a, b))) {
50
+ groups.push({ group: folderTitle(folder), pages: toPages(child) });
51
+ }
52
+ return {
53
+ $schema: 'https://mintlify.com/docs.json',
54
+ theme: 'mint',
55
+ name,
56
+ colors: { primary: '#16A34A' },
57
+ navigation: { groups },
58
+ };
59
+ };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './fs/index.js';
2
2
  export * from './generate.js';
3
+ export * from './generate-docs-config.js';
3
4
  export * from './utils.js';
4
5
  export * from './prebuild/index.js';
5
6
  export { getFaviconsConfig } from './prebuild/generateFavicons.js';
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './fs/index.js';
2
2
  export * from './generate.js';
3
+ export * from './generate-docs-config.js';
3
4
  export * from './utils.js';
4
5
  export * from './prebuild/index.js';
5
6
  export { getFaviconsConfig } from './prebuild/generateFavicons.js';