@mintlify/common 1.0.1189 → 1.0.1190
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,3 +1,9 @@
|
|
|
1
1
|
import { NavigationConfig, PagesConfig } from '@mintlify/validation';
|
|
2
|
+
type DivisionContext = {
|
|
3
|
+
language?: string;
|
|
4
|
+
isDefaultLanguage?: boolean;
|
|
5
|
+
version?: string;
|
|
6
|
+
};
|
|
2
7
|
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;
|
|
8
|
+
export declare function generatePathToBreadcrumbsMapForPagesRecursive(pages: PagesConfig, currentBreadcrumbs: string[], map: Map<string, string[]>, depth?: number, pathPriorities?: Map<string, number>, divisionContext?: DivisionContext): void;
|
|
9
|
+
export {};
|
|
@@ -17,14 +17,37 @@ function getDivisionTitle(item, key) {
|
|
|
17
17
|
return getStringProperty(item, divisionPropertyNameMap[key]);
|
|
18
18
|
}
|
|
19
19
|
const MAX_RECURSION_DEPTH = 100;
|
|
20
|
+
function getDefaultLanguage(items) {
|
|
21
|
+
var _a;
|
|
22
|
+
const defaultItem = (_a = items.find((item) => Reflect.get(item, 'default') === true)) !== null && _a !== void 0 ? _a : items[0];
|
|
23
|
+
return defaultItem ? getStringProperty(defaultItem, 'language') : '';
|
|
24
|
+
}
|
|
25
|
+
function getPathPriority(path, { language, isDefaultLanguage, version }) {
|
|
26
|
+
if (!language)
|
|
27
|
+
return 0;
|
|
28
|
+
const localePrefixes = version ? [`${language}/`, `${version}/${language}/`] : [`${language}/`];
|
|
29
|
+
if (localePrefixes.some((prefix) => path.startsWith(prefix)))
|
|
30
|
+
return 2;
|
|
31
|
+
return isDefaultLanguage ? 1 : 0;
|
|
32
|
+
}
|
|
33
|
+
function getItemDivisionContext(key, item, divisionContext, defaultLanguage) {
|
|
34
|
+
if (key === 'languages') {
|
|
35
|
+
const language = getStringProperty(item, 'language');
|
|
36
|
+
return Object.assign(Object.assign({}, divisionContext), { language, isDefaultLanguage: language === defaultLanguage });
|
|
37
|
+
}
|
|
38
|
+
if (key === 'versions') {
|
|
39
|
+
return Object.assign(Object.assign({}, divisionContext), { version: getStringProperty(item, 'version') });
|
|
40
|
+
}
|
|
41
|
+
return divisionContext;
|
|
42
|
+
}
|
|
20
43
|
export function generatePathToBreadcrumbsMapForDocsConfig(navigation) {
|
|
21
44
|
const pathToBreadcrumbs = new Map();
|
|
22
|
-
generatePathToBreadcrumbsMapForDocsConfigRecursive(navigation, pathToBreadcrumbs, []);
|
|
45
|
+
generatePathToBreadcrumbsMapForDocsConfigRecursive(navigation, pathToBreadcrumbs, [], new Map());
|
|
23
46
|
return pathToBreadcrumbs;
|
|
24
47
|
}
|
|
25
|
-
function generatePathToBreadcrumbsMapForDocsConfigRecursive(nav, map, currentBreadcrumbs =
|
|
48
|
+
function generatePathToBreadcrumbsMapForDocsConfigRecursive(nav, map, currentBreadcrumbs, pathPriorities, divisionContext = {}) {
|
|
26
49
|
if ('pages' in nav) {
|
|
27
|
-
generatePathToBreadcrumbsMapForPagesRecursive(nav.pages, currentBreadcrumbs, map);
|
|
50
|
+
generatePathToBreadcrumbsMapForPagesRecursive(nav.pages, currentBreadcrumbs, map, 0, pathPriorities, divisionContext);
|
|
28
51
|
}
|
|
29
52
|
for (const key of [...divisions, 'groups']) {
|
|
30
53
|
if (key in nav) {
|
|
@@ -33,28 +56,34 @@ function generatePathToBreadcrumbsMapForDocsConfigRecursive(nav, map, currentBre
|
|
|
33
56
|
continue;
|
|
34
57
|
}
|
|
35
58
|
const includeDivisionInBreadcrumbs = key === 'groups' || !excludedBreadcrumbDivisions.has(key);
|
|
59
|
+
const defaultLanguage = key === 'languages' ? getDefaultLanguage(items) : undefined;
|
|
36
60
|
for (const item of items) {
|
|
37
61
|
const divisionTitle = includeDivisionInBreadcrumbs ? getDivisionTitle(item, key) : '';
|
|
38
62
|
const newBreadcrumbs = divisionTitle
|
|
39
63
|
? [...currentBreadcrumbs, divisionTitle]
|
|
40
64
|
: currentBreadcrumbs;
|
|
41
|
-
generatePathToBreadcrumbsMapForDocsConfigRecursive(item, map, newBreadcrumbs);
|
|
65
|
+
generatePathToBreadcrumbsMapForDocsConfigRecursive(item, map, newBreadcrumbs, pathPriorities, getItemDivisionContext(key, item, divisionContext, defaultLanguage));
|
|
42
66
|
}
|
|
43
67
|
}
|
|
44
68
|
}
|
|
45
69
|
}
|
|
46
|
-
export function generatePathToBreadcrumbsMapForPagesRecursive(pages, currentBreadcrumbs, map, depth = 0) {
|
|
70
|
+
export function generatePathToBreadcrumbsMapForPagesRecursive(pages, currentBreadcrumbs, map, depth = 0, pathPriorities = new Map(), divisionContext = {}) {
|
|
71
|
+
var _a;
|
|
47
72
|
if (depth >= MAX_RECURSION_DEPTH)
|
|
48
73
|
return;
|
|
49
74
|
for (const entry of pages) {
|
|
50
75
|
if (typeof entry === 'string') {
|
|
76
|
+
const priority = getPathPriority(entry, divisionContext);
|
|
77
|
+
if (((_a = pathPriorities.get(entry)) !== null && _a !== void 0 ? _a : -1) > priority)
|
|
78
|
+
continue;
|
|
51
79
|
const nonEmptyBreadcrumbs = currentBreadcrumbs.filter((crumb) => !!crumb.trim());
|
|
52
80
|
map.set(entry, [...nonEmptyBreadcrumbs]);
|
|
81
|
+
pathPriorities.set(entry, priority);
|
|
53
82
|
}
|
|
54
83
|
else {
|
|
55
84
|
currentBreadcrumbs.push(entry.group);
|
|
56
85
|
if ('pages' in entry && Array.isArray(entry.pages)) {
|
|
57
|
-
generatePathToBreadcrumbsMapForPagesRecursive(entry.pages, currentBreadcrumbs, map, depth + 1);
|
|
86
|
+
generatePathToBreadcrumbsMapForPagesRecursive(entry.pages, currentBreadcrumbs, map, depth + 1, pathPriorities, divisionContext);
|
|
58
87
|
}
|
|
59
88
|
currentBreadcrumbs.pop();
|
|
60
89
|
}
|