@mintlify/common 1.0.1264 → 1.0.1266
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.
- package/dist/navigation/filterDivisions.d.ts +2 -1
- package/dist/navigation/filterDivisions.js +3 -3
- package/dist/navigation/isCommonPage.js +3 -2
- package/dist/navigation/pathsDifferByOneSegment.test.js +8 -0
- package/dist/navigation/scopeNavToPath.js +1 -0
- package/dist/navigation/updateFirstHrefInDivision.js +37 -15
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +3 -3
|
@@ -10,6 +10,7 @@ export type FilterDivisionsParams = {
|
|
|
10
10
|
userGroups: Set<string>;
|
|
11
11
|
isPreview?: boolean;
|
|
12
12
|
shouldUseDivisionMatch: boolean;
|
|
13
|
+
skipDivisionTargets?: boolean;
|
|
13
14
|
cache: {
|
|
14
15
|
dropdownCache: Map<string, string>;
|
|
15
16
|
};
|
|
@@ -54,7 +55,7 @@ export type NavigationDivisions = {
|
|
|
54
55
|
products: Array<ProductsResult>;
|
|
55
56
|
menu: Array<MenuResult>;
|
|
56
57
|
};
|
|
57
|
-
export declare const filterDivisions: ({ currentPath, currentVersion, currentLanguage, currentProduct, decoratedNav, userGroups, shouldUseDivisionMatch, cache, isPreview, }: FilterDivisionsParams) => FilterDivisionsResult;
|
|
58
|
+
export declare const filterDivisions: ({ currentPath, currentVersion, currentLanguage, currentProduct, decoratedNav, userGroups, shouldUseDivisionMatch, skipDivisionTargets, cache, isPreview, }: FilterDivisionsParams) => FilterDivisionsResult;
|
|
58
59
|
/**
|
|
59
60
|
* TODO: we should add cache for versions and languages in the future
|
|
60
61
|
* Generate a cache key for the dropdowns
|
|
@@ -34,7 +34,7 @@ function reorderForCurrentProduct(items, currentProduct) {
|
|
|
34
34
|
return items;
|
|
35
35
|
return [match, ...items.slice(0, idx), ...items.slice(idx + 1)];
|
|
36
36
|
}
|
|
37
|
-
export const filterDivisions = ({ currentPath, currentVersion, currentLanguage, currentProduct, decoratedNav, userGroups, shouldUseDivisionMatch = true, cache, isPreview = false, }) => {
|
|
37
|
+
export const filterDivisions = ({ currentPath, currentVersion, currentLanguage, currentProduct, decoratedNav, userGroups, shouldUseDivisionMatch = true, skipDivisionTargets = false, cache, isPreview = false, }) => {
|
|
38
38
|
var _a, _b, _c;
|
|
39
39
|
let navigationDivisions = {
|
|
40
40
|
tabs: [],
|
|
@@ -204,7 +204,7 @@ export const filterDivisions = ({ currentPath, currentVersion, currentLanguage,
|
|
|
204
204
|
}
|
|
205
205
|
if (filteredGroupsOrPages && filteredGroupsOrPages.length)
|
|
206
206
|
groups = filteredGroupsOrPages;
|
|
207
|
-
if (navigationDivisions.versions.length) {
|
|
207
|
+
if (!skipDivisionTargets && navigationDivisions.versions.length) {
|
|
208
208
|
updateFirstHrefInDivision({
|
|
209
209
|
type: 'version',
|
|
210
210
|
currentPath,
|
|
@@ -221,7 +221,7 @@ export const filterDivisions = ({ currentPath, currentVersion, currentLanguage,
|
|
|
221
221
|
activeDivisionOwner: activeVersionsOwner,
|
|
222
222
|
});
|
|
223
223
|
}
|
|
224
|
-
if (navigationDivisions.languages.length) {
|
|
224
|
+
if (!skipDivisionTargets && navigationDivisions.languages.length) {
|
|
225
225
|
updateFirstHrefInDivision({
|
|
226
226
|
type: 'language',
|
|
227
227
|
currentPath,
|
|
@@ -13,15 +13,16 @@ export function isCommonPage(entry, path) {
|
|
|
13
13
|
isCommonPageRecursive(entry, path, occurrences);
|
|
14
14
|
return occurrences.value > 1;
|
|
15
15
|
}
|
|
16
|
+
const CHILD_KEYS = [...divisions, 'groups', 'pages'];
|
|
16
17
|
function isCommonPageRecursive(entry, path, occurrences) {
|
|
17
|
-
if (typeof entry !== 'object')
|
|
18
|
+
if (typeof entry !== 'object' || occurrences.value > 1)
|
|
18
19
|
return;
|
|
19
20
|
if (isPage(entry)) {
|
|
20
21
|
if (isEqualIgnoringLeadingSlash(entry.href, path)) {
|
|
21
22
|
occurrences.value++;
|
|
22
23
|
}
|
|
23
24
|
}
|
|
24
|
-
for (const key of
|
|
25
|
+
for (const key of CHILD_KEYS) {
|
|
25
26
|
if (key === 'pages' && 'root' in entry && typeof entry.root === 'object') {
|
|
26
27
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- root is a DecoratedNavigationPage
|
|
27
28
|
isCommonPageRecursive(entry.root, path, occurrences);
|
|
@@ -149,3 +149,11 @@ describe('pathsDifferByOneSegment', () => {
|
|
|
149
149
|
});
|
|
150
150
|
});
|
|
151
151
|
});
|
|
152
|
+
describe('pathsDifferByOneSegment configured languages', () => {
|
|
153
|
+
it('sees languages added to the same array in place', () => {
|
|
154
|
+
const languages = ['zz'];
|
|
155
|
+
expect(pathsDifferByOneSegment('/tlh/guide', '/guide', 'language', languages)).toBe(false);
|
|
156
|
+
languages.push('tlh');
|
|
157
|
+
expect(pathsDifferByOneSegment('/tlh/guide', '/guide', 'language', languages)).toBe(true);
|
|
158
|
+
});
|
|
159
|
+
});
|
|
@@ -592,6 +592,7 @@ export function getScopedNavForPath({ decoratedNav, currentPath, userGroups = ne
|
|
|
592
592
|
currentLanguage: undefined,
|
|
593
593
|
currentProduct,
|
|
594
594
|
shouldUseDivisionMatch: false,
|
|
595
|
+
skipDivisionTargets: true,
|
|
595
596
|
cache: { dropdownCache: new Map() },
|
|
596
597
|
isPreview,
|
|
597
598
|
});
|
|
@@ -107,7 +107,7 @@ export function updateFirstHrefInDivision({ type, currentPath, entry, parentGrou
|
|
|
107
107
|
});
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
|
-
for (const key of
|
|
110
|
+
for (const key of divisions) {
|
|
111
111
|
const subDivisions = readObjectArrayProperty(entry, key);
|
|
112
112
|
if (!subDivisions)
|
|
113
113
|
continue;
|
|
@@ -165,10 +165,7 @@ export function updateFirstHrefInDivision({ type, currentPath, entry, parentGrou
|
|
|
165
165
|
type,
|
|
166
166
|
currentPath,
|
|
167
167
|
entry: subDivision,
|
|
168
|
-
parentGroups
|
|
169
|
-
? // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
170
|
-
entry.groups
|
|
171
|
-
: parentGroups,
|
|
168
|
+
parentGroups,
|
|
172
169
|
nearestDivisionValue: divisionValue !== null && divisionValue !== void 0 ? divisionValue : nearestDivisionValue,
|
|
173
170
|
isActiveGroup,
|
|
174
171
|
inActiveDivision: inActiveDivision,
|
|
@@ -220,14 +217,37 @@ function findActiveGroupNames(entry, currentPath, activeGroupNames = new Set())
|
|
|
220
217
|
}
|
|
221
218
|
return activeGroupNames;
|
|
222
219
|
}
|
|
220
|
+
const NO_LANGUAGES = [];
|
|
221
|
+
let lastLanguageSet;
|
|
222
|
+
function getLowerCaseLanguageSet(languages) {
|
|
223
|
+
const cached = lastLanguageSet;
|
|
224
|
+
if ((cached === null || cached === void 0 ? void 0 : cached.languages.length) === languages.length &&
|
|
225
|
+
cached.languages.every((language, i) => language === languages[i])) {
|
|
226
|
+
return cached.set;
|
|
227
|
+
}
|
|
228
|
+
const set = new Set(languages.map((language) => language.toLowerCase()));
|
|
229
|
+
lastLanguageSet = { languages: [...languages], set };
|
|
230
|
+
return set;
|
|
231
|
+
}
|
|
223
232
|
const isLanguageSegment = (segment, languages) => {
|
|
224
233
|
if (segment === undefined)
|
|
225
234
|
return false;
|
|
226
|
-
|
|
227
|
-
return true;
|
|
228
|
-
const lowerCaseSegment = segment.toLowerCase();
|
|
229
|
-
return languages.some((language) => language.toLowerCase() === lowerCaseSegment);
|
|
235
|
+
return isKnownLocale(segment) || languages.has(segment.toLowerCase());
|
|
230
236
|
};
|
|
237
|
+
const toSegments = (path) => path.split('/').filter(Boolean);
|
|
238
|
+
let lastTarget;
|
|
239
|
+
function getTarget(path, languages) {
|
|
240
|
+
if ((lastTarget === null || lastTarget === void 0 ? void 0 : lastTarget.path) !== path || lastTarget.languages !== languages) {
|
|
241
|
+
const segments = toSegments(path);
|
|
242
|
+
lastTarget = {
|
|
243
|
+
path,
|
|
244
|
+
languages,
|
|
245
|
+
segments,
|
|
246
|
+
languagePath: parseLanguagePath(segments, languages),
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
return lastTarget;
|
|
250
|
+
}
|
|
231
251
|
function parseLanguagePath(segments, languages) {
|
|
232
252
|
let index = 0;
|
|
233
253
|
let locale;
|
|
@@ -340,19 +360,21 @@ function maybeUpdateFirstHrefInDivision(type, href, finalVersion, inActiveGroup,
|
|
|
340
360
|
}
|
|
341
361
|
}
|
|
342
362
|
}
|
|
343
|
-
export function pathsDifferByOneSegment(a, b, type, languages =
|
|
363
|
+
export function pathsDifferByOneSegment(a, b, type, languages = NO_LANGUAGES) {
|
|
344
364
|
var _a, _b;
|
|
345
|
-
const
|
|
346
|
-
const
|
|
365
|
+
const languageSet = getLowerCaseLanguageSet(languages);
|
|
366
|
+
const aSegments = toSegments(a);
|
|
367
|
+
const target = getTarget(b, languageSet);
|
|
368
|
+
const bSegments = target.segments;
|
|
347
369
|
// For language switching, we need to be more strict - paths should be identical except for the language segment
|
|
348
370
|
// once normalized, content segments should be identical and only locale prefix may differ.
|
|
349
371
|
if (type === 'language') {
|
|
350
|
-
const aPath = parseLanguagePath(aSegments,
|
|
351
|
-
const bPath =
|
|
372
|
+
const aPath = parseLanguagePath(aSegments, languageSet);
|
|
373
|
+
const bPath = target.languagePath;
|
|
352
374
|
if (aPath.hasDocsBase !== bPath.hasDocsBase)
|
|
353
375
|
return false;
|
|
354
376
|
if (!aPath.locale && !bPath.locale) {
|
|
355
|
-
return differByOneLocaleSegment(aPath.contentSegments, bPath.contentSegments,
|
|
377
|
+
return differByOneLocaleSegment(aPath.contentSegments, bPath.contentSegments, languageSet);
|
|
356
378
|
}
|
|
357
379
|
// For language switching, the content parts (including version segments) must be identical.
|
|
358
380
|
if (aPath.contentSegments.length !== bPath.contentSegments.length)
|