@mintlify/common 1.0.1298 → 1.0.1300
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.
|
@@ -291,13 +291,17 @@ function buildDivisionItem(param) {
|
|
|
291
291
|
const divisionItem = Object.fromEntries(Object.entries(item).filter(([key]) => !keysToDrop.includes(key)));
|
|
292
292
|
// if href is absolute url, use it, otherwise use the href from the first page
|
|
293
293
|
if (!href) {
|
|
294
|
-
const
|
|
294
|
+
const userHref = 'href' in item ? item.href : undefined;
|
|
295
|
+
const hasChildNav = divisionKey === 'languages' || keysToDrop.some((key) => key in item);
|
|
296
|
+
const isUserDefinedHref = !!userHref &&
|
|
297
|
+
(isAbsoluteUrl(userHref) ||
|
|
298
|
+
(!hasChildNav && userHref.startsWith('/') && !userHref.startsWith('//')));
|
|
295
299
|
if (!isUserDefinedHref && divisionKey === 'dropdowns' && !isActive && currentPath) {
|
|
296
300
|
href =
|
|
297
301
|
(_c = (_b = findCorrespondingDropdownHref(item, currentPath, userGroups !== null && userGroups !== void 0 ? userGroups : new Set(), isPreview)) !== null && _b !== void 0 ? _b : findSamePageInDropdownVersion(page === null || page === void 0 ? void 0 : page.href, findDivisionName(item), currentPath, rootNav, userGroups !== null && userGroups !== void 0 ? userGroups : new Set(), isPreview)) !== null && _c !== void 0 ? _c : '';
|
|
298
302
|
}
|
|
299
303
|
if (!href) {
|
|
300
|
-
href = isUserDefinedHref ?
|
|
304
|
+
href = isUserDefinedHref ? userHref : (page === null || page === void 0 ? void 0 : page.href) || '/';
|
|
301
305
|
// when users switch languages, we should stay on the same page
|
|
302
306
|
// instead of switching to the first page in the new language
|
|
303
307
|
if (!isUserDefinedHref && divisionKey === 'languages') {
|
|
@@ -970,3 +970,78 @@ describe('filterDivisions dropdown corresponding pages', () => {
|
|
|
970
970
|
});
|
|
971
971
|
});
|
|
972
972
|
});
|
|
973
|
+
describe('filterDivisions root-relative division hrefs', () => {
|
|
974
|
+
const defaultArgs = {
|
|
975
|
+
decoratedNav: { groups: [] },
|
|
976
|
+
currentPath: '/guides/intro',
|
|
977
|
+
userGroups: new Set(),
|
|
978
|
+
currentVersion: '',
|
|
979
|
+
currentLanguage: undefined,
|
|
980
|
+
shouldUseDivisionMatch: true,
|
|
981
|
+
cache: {
|
|
982
|
+
dropdownCache: new Map(),
|
|
983
|
+
},
|
|
984
|
+
};
|
|
985
|
+
const guidesGroups = [{ group: 'Start', pages: [{ title: 'Intro', href: '/guides/intro' }] }];
|
|
986
|
+
const platformGroups = [
|
|
987
|
+
{ group: 'Platform', pages: [{ title: 'Analytics', href: '/platform/analytics' }] },
|
|
988
|
+
];
|
|
989
|
+
it.each(['tabs', 'anchors', 'dropdowns'])('uses a root-relative href on %s without child navigation', (key) => {
|
|
990
|
+
var _a;
|
|
991
|
+
const divisionName = { tabs: 'tab', anchors: 'anchor', dropdowns: 'dropdown' }[key];
|
|
992
|
+
const result = filterDivisions(Object.assign(Object.assign({}, defaultArgs), { decoratedNav: {
|
|
993
|
+
[key]: [
|
|
994
|
+
{ [divisionName]: 'Guides', groups: guidesGroups },
|
|
995
|
+
{ [divisionName]: 'Analytics', href: '/platform/analytics' },
|
|
996
|
+
],
|
|
997
|
+
} }));
|
|
998
|
+
expect((_a = result[key].find((d) => d.name === 'Analytics')) === null || _a === void 0 ? void 0 : _a.href).toBe('/platform/analytics');
|
|
999
|
+
});
|
|
1000
|
+
it('uses a root-relative href on a menu item without child navigation', () => {
|
|
1001
|
+
var _a, _b;
|
|
1002
|
+
const result = filterDivisions(Object.assign(Object.assign({}, defaultArgs), { decoratedNav: {
|
|
1003
|
+
tabs: [
|
|
1004
|
+
{
|
|
1005
|
+
tab: 'Guides',
|
|
1006
|
+
menu: [
|
|
1007
|
+
{ item: 'Intro', groups: guidesGroups },
|
|
1008
|
+
{ item: 'Analytics', href: '/platform/analytics' },
|
|
1009
|
+
],
|
|
1010
|
+
},
|
|
1011
|
+
{ tab: 'Platform', groups: platformGroups },
|
|
1012
|
+
],
|
|
1013
|
+
} }));
|
|
1014
|
+
const menu = (_a = result.tabs.find((t) => t.name === 'Guides')) === null || _a === void 0 ? void 0 : _a.menu;
|
|
1015
|
+
expect((_b = menu === null || menu === void 0 ? void 0 : menu.find((m) => m.name === 'Analytics')) === null || _b === void 0 ? void 0 : _b.href).toBe('/platform/analytics');
|
|
1016
|
+
});
|
|
1017
|
+
it('keeps the first page href when the division also has child navigation', () => {
|
|
1018
|
+
var _a;
|
|
1019
|
+
const result = filterDivisions(Object.assign(Object.assign({}, defaultArgs), { decoratedNav: {
|
|
1020
|
+
tabs: [
|
|
1021
|
+
{ tab: 'Guides', groups: guidesGroups },
|
|
1022
|
+
{ tab: 'Platform', href: '/elsewhere', groups: platformGroups },
|
|
1023
|
+
],
|
|
1024
|
+
} }));
|
|
1025
|
+
expect((_a = result.tabs.find((t) => t.name === 'Platform')) === null || _a === void 0 ? void 0 : _a.href).toBe('/platform/analytics');
|
|
1026
|
+
});
|
|
1027
|
+
it('leaves language hrefs on the current page', () => {
|
|
1028
|
+
var _a;
|
|
1029
|
+
const result = filterDivisions(Object.assign(Object.assign({}, defaultArgs), { decoratedNav: {
|
|
1030
|
+
languages: [
|
|
1031
|
+
{ language: 'en', groups: guidesGroups },
|
|
1032
|
+
{ language: 'fr', href: '/fr/guides/intro' },
|
|
1033
|
+
],
|
|
1034
|
+
} }));
|
|
1035
|
+
expect((_a = result.languages.find((l) => l.language === 'fr')) === null || _a === void 0 ? void 0 : _a.href).toBe('');
|
|
1036
|
+
});
|
|
1037
|
+
it('does not treat protocol-relative hrefs as internal', () => {
|
|
1038
|
+
var _a;
|
|
1039
|
+
const result = filterDivisions(Object.assign(Object.assign({}, defaultArgs), { decoratedNav: {
|
|
1040
|
+
tabs: [
|
|
1041
|
+
{ tab: 'Guides', groups: guidesGroups },
|
|
1042
|
+
{ tab: 'Other', href: '//evil.example.com' },
|
|
1043
|
+
],
|
|
1044
|
+
} }));
|
|
1045
|
+
expect((_a = result.tabs.find((t) => t.name === 'Other')) === null || _a === void 0 ? void 0 : _a.href).toBe('/');
|
|
1046
|
+
});
|
|
1047
|
+
});
|