@mintlify/common 1.0.789 → 1.0.791

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,2 @@
1
+ import { NavigationConfig, DivisionNavigationType } from '@mintlify/validation';
2
+ export declare function getFirstPageFromNavConfig(nav: NavigationConfig | DivisionNavigationType | undefined): string | undefined;
@@ -0,0 +1,48 @@
1
+ import { divisions, } from '@mintlify/validation';
2
+ import { replaceSlashIndex } from '../slug/replaceSlashIndex.js';
3
+ function getFirstFromPageOrGroup(entry) {
4
+ if (typeof entry === 'string') {
5
+ return replaceSlashIndex(entry);
6
+ }
7
+ if ('hidden' in entry && entry.hidden)
8
+ return undefined;
9
+ return getFirstPageFromNavConfig(entry);
10
+ }
11
+ export function getFirstPageFromNavConfig(nav) {
12
+ if (!nav || typeof nav !== 'object')
13
+ return undefined;
14
+ if ('pages' in nav && nav.pages) {
15
+ if ('root' in nav && typeof nav.root === 'string') {
16
+ return replaceSlashIndex(nav.root);
17
+ }
18
+ for (const page of nav.pages) {
19
+ const result = getFirstFromPageOrGroup(page);
20
+ if (result !== undefined)
21
+ return result;
22
+ }
23
+ }
24
+ if ('groups' in nav) {
25
+ for (const group of nav.groups) {
26
+ if (group.hidden)
27
+ continue;
28
+ const result = getFirstPageFromNavConfig(group);
29
+ if (result !== undefined)
30
+ return result;
31
+ }
32
+ }
33
+ for (const key of divisions) {
34
+ if (key in nav) {
35
+ const items = nav[key];
36
+ if (Array.isArray(items)) {
37
+ for (const item of items) {
38
+ if (typeof item === 'object' && 'hidden' in item && item.hidden)
39
+ continue;
40
+ const result = getFirstPageFromNavConfig(item);
41
+ if (result !== undefined)
42
+ return result;
43
+ }
44
+ }
45
+ }
46
+ }
47
+ return undefined;
48
+ }
@@ -5,3 +5,4 @@ export * from './getFirstPageFromNavigation.js';
5
5
  export * from './generatePathToBreadcrumbsMapForDocsConfig.js';
6
6
  export * from './getAllPathsInDocsNav.js';
7
7
  export * from './checkNavAccess.js';
8
+ export * from './getFirstPageFromNavConfig.js';
@@ -5,3 +5,4 @@ export * from './getFirstPageFromNavigation.js';
5
5
  export * from './generatePathToBreadcrumbsMapForDocsConfig.js';
6
6
  export * from './getAllPathsInDocsNav.js';
7
7
  export * from './checkNavAccess.js';
8
+ export * from './getFirstPageFromNavConfig.js';