@mintlify/common 1.0.433 → 1.0.435

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.
@@ -1,2 +1,3 @@
1
- import { NavigationConfig } from '@mintlify/validation';
1
+ import { NavigationConfig, PagesConfig } from '@mintlify/validation';
2
2
  export declare function generatePathToBreadcrumbsMapForDocsConfig(navigation: NavigationConfig): Map<any, any>;
3
+ export declare function generatePathToBreadcrumbsMapForPagesRecursive(pages: PagesConfig, currentBreadcrumbs: string[], map: Map<string, string[]>, depth?: number): void;
@@ -1,18 +1,15 @@
1
1
  import { divisions } from '@mintlify/validation';
2
- import { generatePathToBreadcrumbsMapRecursive } from './generatePathToBreadcrumbsMap.js';
2
+ const MAX_RECURSION_DEPTH = 100;
3
3
  export function generatePathToBreadcrumbsMapForDocsConfig(navigation) {
4
4
  const pathToBreadcrumbs = new Map();
5
5
  generatePathToBreadcrumbsMapForDocsConfigRecursive(navigation, pathToBreadcrumbs, []);
6
6
  return pathToBreadcrumbs;
7
7
  }
8
8
  function generatePathToBreadcrumbsMapForDocsConfigRecursive(nav, map, currentBreadcrumbs = []) {
9
- if ('groups' in nav) {
10
- for (const group of nav.groups) {
11
- generatePathToBreadcrumbsMapRecursive(group, currentBreadcrumbs, map);
12
- }
13
- return;
9
+ if ('pages' in nav) {
10
+ generatePathToBreadcrumbsMapForPagesRecursive(nav.pages, currentBreadcrumbs, map);
14
11
  }
15
- for (const key of divisions) {
12
+ for (const key of [...divisions, 'groups']) {
16
13
  if (key in nav) {
17
14
  const items = nav[key];
18
15
  if (!Array.isArray(items)) {
@@ -31,6 +28,9 @@ function generatePathToBreadcrumbsMapForDocsConfigRecursive(nav, map, currentBre
31
28
  else if (key === 'anchors' && 'anchor' in item && typeof item.anchor === 'string') {
32
29
  divisionTitle = item.anchor;
33
30
  }
31
+ else if (key === 'groups' && 'group' in item && typeof item.group === 'string') {
32
+ divisionTitle = item.group;
33
+ }
34
34
  const newBreadcrumbs = divisionTitle
35
35
  ? [...currentBreadcrumbs, divisionTitle]
36
36
  : currentBreadcrumbs;
@@ -39,3 +39,20 @@ function generatePathToBreadcrumbsMapForDocsConfigRecursive(nav, map, currentBre
39
39
  }
40
40
  }
41
41
  }
42
+ export function generatePathToBreadcrumbsMapForPagesRecursive(pages, currentBreadcrumbs, map, depth = 0) {
43
+ if (depth >= MAX_RECURSION_DEPTH)
44
+ return;
45
+ for (const entry of pages) {
46
+ if (typeof entry === 'object' && 'group' in entry && typeof entry.group === 'string') {
47
+ currentBreadcrumbs.push(entry.group);
48
+ if ('pages' in entry && Array.isArray(entry.pages)) {
49
+ generatePathToBreadcrumbsMapForPagesRecursive(entry.pages, currentBreadcrumbs, map, depth + 1);
50
+ }
51
+ currentBreadcrumbs.pop();
52
+ }
53
+ else {
54
+ const nonEmptyBreadcrumbs = currentBreadcrumbs.filter((crumb) => !!crumb.trim());
55
+ map.set(entry, [...nonEmptyBreadcrumbs]);
56
+ }
57
+ }
58
+ }