@mintlify/common 1.0.993 → 1.0.994

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,6 @@
1
+ import { DecoratedNavigationConfig } from '@mintlify/validation';
2
+ /**
3
+ * Assumes page hrefs in navWithPageContext have a leading / but config page paths do not.
4
+ * Outputted dictionary will NOT have a leading / in the dictionary keys.
5
+ */
6
+ export declare function generatePathToProductDict(decoratedNav: DecoratedNavigationConfig): Map<string, string | undefined>;
@@ -0,0 +1,45 @@
1
+ import { divisions, } from '@mintlify/validation';
2
+ import { isPage } from '../navigation/isPage.js';
3
+ import { optionallyRemoveLeadingSlash } from '../optionallyRemoveLeadingSlash.js';
4
+ import { iterateObjectArrayProperty } from './iterateObjectArrayProperty.js';
5
+ /**
6
+ * Assumes page hrefs in navWithPageContext have a leading / but config page paths do not.
7
+ * Outputted dictionary will NOT have a leading / in the dictionary keys.
8
+ */
9
+ export function generatePathToProductDict(decoratedNav) {
10
+ const pathToProductDict = new Map();
11
+ generatePathToProductDictRecursive(pathToProductDict, decoratedNav);
12
+ return pathToProductDict;
13
+ }
14
+ function generatePathToProductDictRecursive(pathToProductDict, nav, nearestProduct) {
15
+ if (typeof nav !== 'object')
16
+ return;
17
+ if (isPage(nav)) {
18
+ const key = optionallyRemoveLeadingSlash(nav.href);
19
+ const existingProduct = pathToProductDict.get(key);
20
+ if (!pathToProductDict.has(key)) {
21
+ pathToProductDict.set(key, nearestProduct);
22
+ }
23
+ else if (existingProduct !== undefined && existingProduct !== nearestProduct) {
24
+ pathToProductDict.set(key, undefined);
25
+ }
26
+ }
27
+ if ('pages' in nav && Array.isArray(nav.pages)) {
28
+ if ('root' in nav && typeof nav.root === 'object') {
29
+ generatePathToProductDictRecursive(pathToProductDict, nav.root, nearestProduct);
30
+ }
31
+ for (const page of nav.pages) {
32
+ if (typeof page === 'object') {
33
+ generatePathToProductDictRecursive(pathToProductDict, page, nearestProduct);
34
+ }
35
+ }
36
+ }
37
+ for (const key of ['groups', ...divisions]) {
38
+ iterateObjectArrayProperty(nav, key, (item) => {
39
+ let product = nearestProduct;
40
+ if (key === 'products')
41
+ product = item.product;
42
+ generatePathToProductDictRecursive(pathToProductDict, item, product);
43
+ });
44
+ }
45
+ }
@@ -4,5 +4,6 @@ export * from './generatePathToHiddenFromSearchDict.js';
4
4
  export * from './generatePathToVersionDict.js';
5
5
  export * from './generatePathToVersionDictForDocsConfig.js';
6
6
  export * from './generatePathToLanguageDict.js';
7
+ export * from './generatePathToProductDict.js';
7
8
  export * from './generatePathToPublicDict.js';
8
9
  export * from './generatePathToBoostDict.js';
@@ -4,5 +4,6 @@ export * from './generatePathToHiddenFromSearchDict.js';
4
4
  export * from './generatePathToVersionDict.js';
5
5
  export * from './generatePathToVersionDictForDocsConfig.js';
6
6
  export * from './generatePathToLanguageDict.js';
7
+ export * from './generatePathToProductDict.js';
7
8
  export * from './generatePathToPublicDict.js';
8
9
  export * from './generatePathToBoostDict.js';