@mintlify/common 1.0.1235 → 1.0.1237
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/mdx/snippets/resolveAllImports.js +10 -1
- package/dist/mdx/snippets/resolveImport/resolveComponentWithContent.js +3 -1
- package/dist/navigation/updateFirstHrefInDivision.d.ts +8 -1
- package/dist/navigation/updateFirstHrefInDivision.js +26 -4
- package/dist/navigation/updateFirstHrefInDivision.test.js +61 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +3 -3
|
@@ -100,7 +100,16 @@ export const resolveAllImports = (params) => __awaiter(void 0, void 0, void 0, f
|
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
102
|
try {
|
|
103
|
-
const contentWithResolvedImport = yield resolveImport(specifier, ast, importedSnippet.tree, exportMap,
|
|
103
|
+
const contentWithResolvedImport = yield resolveImport(specifier, ast, importedSnippet.tree, exportMap, (warning) => {
|
|
104
|
+
// the collision itself doesn't know which page it happened in, so add it here
|
|
105
|
+
const located = Object.assign(Object.assign({}, warning), { message: `${warning.message} (in ${fileWithImports.filename}, importing ${resolvedPath})` });
|
|
106
|
+
if (onWarning) {
|
|
107
|
+
onWarning(located);
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
console.log(located.message);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
104
113
|
if (contentWithResolvedImport == undefined) {
|
|
105
114
|
throw new Error('Import failed to resolve');
|
|
106
115
|
}
|
|
@@ -74,7 +74,9 @@ const replaceVariablesWithProps = (node, treeToInject, exportMap, snippetExportM
|
|
|
74
74
|
return existing;
|
|
75
75
|
let id = 0;
|
|
76
76
|
let uniqueName = createUniqueVariableName(name, id);
|
|
77
|
-
|
|
77
|
+
// Also skip the snippet's own exports: a nested snippet it already inlined declared `prop_0`,
|
|
78
|
+
// and reusing that name would let this tag's value overwrite the nested one
|
|
79
|
+
while (exportMap[uniqueName] || snippetExportMap[uniqueName]) {
|
|
78
80
|
id += 1;
|
|
79
81
|
uniqueName = createUniqueVariableName(name, id);
|
|
80
82
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type PageGroups } from '@mintlify/models';
|
|
1
2
|
import { DecoratedNavigationConfig, DecoratedPageOrGroupConfig, DecoratedGroupConfig } from '@mintlify/validation';
|
|
2
3
|
import { NavigationDivisions } from './filterDivisions.js';
|
|
3
4
|
export declare enum DivisionMatchLevel {
|
|
@@ -11,8 +12,13 @@ export declare enum DivisionMatchLevel {
|
|
|
11
12
|
export type DivisionMatch = {
|
|
12
13
|
href: string;
|
|
13
14
|
matchLevel: DivisionMatchLevel;
|
|
15
|
+
hidden?: true;
|
|
16
|
+
noindex?: true;
|
|
17
|
+
robots?: string;
|
|
18
|
+
canonicalOverride?: true;
|
|
19
|
+
groups?: PageGroups;
|
|
14
20
|
};
|
|
15
|
-
export declare function updateFirstHrefInDivision({ type, currentPath, entry, parentGroups, nearestDivisionValue, isActiveGroup, inActiveDivision, currentDivisionValue, allDivisionValues, firstHrefInDivision, navigationDivisions, isHiddenPage, activeGroupNames, activeDivisionOwner, }: {
|
|
21
|
+
export declare function updateFirstHrefInDivision({ type, currentPath, entry, parentGroups, nearestDivisionValue, isActiveGroup, inActiveDivision, currentDivisionValue, allDivisionValues, firstHrefInDivision, navigationDivisions, isHiddenPage, activeGroupNames, activeDivisionOwner, inHiddenSubtree, }: {
|
|
16
22
|
type: 'version' | 'language';
|
|
17
23
|
currentPath: string;
|
|
18
24
|
entry: DecoratedNavigationConfig | DecoratedPageOrGroupConfig;
|
|
@@ -27,5 +33,6 @@ export declare function updateFirstHrefInDivision({ type, currentPath, entry, pa
|
|
|
27
33
|
isHiddenPage: boolean;
|
|
28
34
|
activeGroupNames?: Set<string>;
|
|
29
35
|
activeDivisionOwner?: object;
|
|
36
|
+
inHiddenSubtree?: boolean;
|
|
30
37
|
}): void;
|
|
31
38
|
export declare function pathsDifferByOneSegment(a: string, b: string, type: 'version' | 'language', languages?: readonly string[]): boolean;
|
|
@@ -13,11 +13,18 @@ export var DivisionMatchLevel;
|
|
|
13
13
|
DivisionMatchLevel[DivisionMatchLevel["UNVERSIONED"] = 5] = "UNVERSIONED";
|
|
14
14
|
})(DivisionMatchLevel || (DivisionMatchLevel = {}));
|
|
15
15
|
const ACCEPTED_BASE_PATHS = ['docs', 'doc', 'documentation', 'help'];
|
|
16
|
-
export function updateFirstHrefInDivision({ type, currentPath, entry, parentGroups, nearestDivisionValue, isActiveGroup, inActiveDivision, currentDivisionValue, allDivisionValues, firstHrefInDivision, navigationDivisions, isHiddenPage, activeGroupNames, activeDivisionOwner, }) {
|
|
16
|
+
export function updateFirstHrefInDivision({ type, currentPath, entry, parentGroups, nearestDivisionValue, isActiveGroup, inActiveDivision, currentDivisionValue, allDivisionValues, firstHrefInDivision, navigationDivisions, isHiddenPage, activeGroupNames, activeDivisionOwner, inHiddenSubtree = false, }) {
|
|
17
17
|
if (typeof entry !== 'object')
|
|
18
18
|
return;
|
|
19
|
+
const hidden = inHiddenSubtree || ('hidden' in entry && entry.hidden === true);
|
|
19
20
|
if (isPage(entry)) {
|
|
20
|
-
maybeUpdateFirstHrefInDivision(type, entry.href, nearestDivisionValue, isActiveGroup, inActiveDivision, currentPath, currentDivisionValue, allDivisionValues, firstHrefInDivision, isHiddenPage
|
|
21
|
+
maybeUpdateFirstHrefInDivision(type, entry.href, nearestDivisionValue, isActiveGroup, inActiveDivision, currentPath, currentDivisionValue, allDivisionValues, firstHrefInDivision, isHiddenPage, {
|
|
22
|
+
hidden,
|
|
23
|
+
noindex: entry.noindex === true,
|
|
24
|
+
robots: entry.robots,
|
|
25
|
+
canonicalOverride: Boolean(entry.canonical),
|
|
26
|
+
groups: entry.groups,
|
|
27
|
+
});
|
|
21
28
|
}
|
|
22
29
|
if ('pages' in entry && Array.isArray(entry.pages)) {
|
|
23
30
|
const root = 'root' in entry && entry.root != null && typeof entry.root === 'object'
|
|
@@ -45,6 +52,7 @@ export function updateFirstHrefInDivision({ type, currentPath, entry, parentGrou
|
|
|
45
52
|
isHiddenPage,
|
|
46
53
|
activeGroupNames,
|
|
47
54
|
activeDivisionOwner,
|
|
55
|
+
inHiddenSubtree: hidden,
|
|
48
56
|
});
|
|
49
57
|
}
|
|
50
58
|
for (const page of entry.pages) {
|
|
@@ -64,6 +72,7 @@ export function updateFirstHrefInDivision({ type, currentPath, entry, parentGrou
|
|
|
64
72
|
isHiddenPage,
|
|
65
73
|
activeGroupNames,
|
|
66
74
|
activeDivisionOwner,
|
|
75
|
+
inHiddenSubtree: hidden,
|
|
67
76
|
});
|
|
68
77
|
}
|
|
69
78
|
}
|
|
@@ -94,6 +103,7 @@ export function updateFirstHrefInDivision({ type, currentPath, entry, parentGrou
|
|
|
94
103
|
isHiddenPage,
|
|
95
104
|
activeGroupNames,
|
|
96
105
|
activeDivisionOwner,
|
|
106
|
+
inHiddenSubtree: hidden,
|
|
97
107
|
});
|
|
98
108
|
}
|
|
99
109
|
}
|
|
@@ -169,6 +179,7 @@ export function updateFirstHrefInDivision({ type, currentPath, entry, parentGrou
|
|
|
169
179
|
isHiddenPage,
|
|
170
180
|
activeGroupNames: activeGroupsInVersionContext,
|
|
171
181
|
activeDivisionOwner,
|
|
182
|
+
inHiddenSubtree: hidden,
|
|
172
183
|
});
|
|
173
184
|
}
|
|
174
185
|
}
|
|
@@ -261,7 +272,7 @@ function parseLanguagePath(segments, languages) {
|
|
|
261
272
|
* @param versionStrings If defined, the array of version strings
|
|
262
273
|
* @param firstHrefInDivision A map from version strings to the href that should be navigated to when switching to that version
|
|
263
274
|
*/
|
|
264
|
-
function maybeUpdateFirstHrefInDivision(type, href, finalVersion, inActiveGroup, inActiveDivision, currentPath, currentVersion, versionStrings, firstHrefInDivision, isHiddenPage) {
|
|
275
|
+
function maybeUpdateFirstHrefInDivision(type, href, finalVersion, inActiveGroup, inActiveDivision, currentPath, currentVersion, versionStrings, firstHrefInDivision, isHiddenPage, target) {
|
|
265
276
|
const versionsToUpdate = finalVersion !== undefined ? [finalVersion] : (versionStrings !== null && versionStrings !== void 0 ? versionStrings : []);
|
|
266
277
|
// now that we support index.mdx, the href might empty string
|
|
267
278
|
// router.push cannot take empty string as url
|
|
@@ -287,7 +298,18 @@ function maybeUpdateFirstHrefInDivision(type, href, finalVersion, inActiveGroup,
|
|
|
287
298
|
const languages = type === 'language' ? versionStrings : undefined;
|
|
288
299
|
if ((existingRef === undefined || DivisionMatchLevel.PATH < existingRef.matchLevel) &&
|
|
289
300
|
pathsDifferByOneSegment(href, currentPath, type, languages)) {
|
|
290
|
-
|
|
301
|
+
const match = { href, matchLevel: DivisionMatchLevel.PATH };
|
|
302
|
+
if (target.hidden)
|
|
303
|
+
match.hidden = true;
|
|
304
|
+
if (target.noindex)
|
|
305
|
+
match.noindex = true;
|
|
306
|
+
if (target.robots)
|
|
307
|
+
match.robots = target.robots;
|
|
308
|
+
if (target.canonicalOverride)
|
|
309
|
+
match.canonicalOverride = true;
|
|
310
|
+
if (target.groups)
|
|
311
|
+
match.groups = target.groups;
|
|
312
|
+
firstHrefInDivision.set(finalVersion, match);
|
|
291
313
|
}
|
|
292
314
|
}
|
|
293
315
|
if (inActiveGroup) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getScopedNavForPath } from './scopeNavToPath.js';
|
|
1
2
|
import { DivisionMatchLevel, updateFirstHrefInDivision, } from './updateFirstHrefInDivision.js';
|
|
2
3
|
const emptyDivisions = {
|
|
3
4
|
tabs: [],
|
|
@@ -50,3 +51,63 @@ describe(updateFirstHrefInDivision, () => {
|
|
|
50
51
|
});
|
|
51
52
|
});
|
|
52
53
|
});
|
|
54
|
+
describe('language translation matches', () => {
|
|
55
|
+
const page = (href, extra = {}) => (Object.assign({ title: href, href }, extra));
|
|
56
|
+
const nav = {
|
|
57
|
+
languages: [
|
|
58
|
+
{
|
|
59
|
+
language: 'en',
|
|
60
|
+
default: true,
|
|
61
|
+
pages: [
|
|
62
|
+
page('/visible'),
|
|
63
|
+
page('/hidden-page'),
|
|
64
|
+
page('/in-hidden-group'),
|
|
65
|
+
page('/gated'),
|
|
66
|
+
page('/noindexed'),
|
|
67
|
+
],
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
language: 'es',
|
|
71
|
+
groups: [
|
|
72
|
+
{
|
|
73
|
+
group: 'Visible',
|
|
74
|
+
pages: [
|
|
75
|
+
page('/es/visible'),
|
|
76
|
+
page('/es/hidden-page', { hidden: true }),
|
|
77
|
+
page('/es/gated', { groups: ['staff'] }),
|
|
78
|
+
page('/es/noindexed', { noindex: true }),
|
|
79
|
+
],
|
|
80
|
+
},
|
|
81
|
+
{ group: 'Hidden', hidden: true, pages: [page('/es/in-hidden-group')] },
|
|
82
|
+
],
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
};
|
|
86
|
+
const esMatch = (currentPath) => getScopedNavForPath({ decoratedNav: nav, currentPath }).firstHrefInLanguage.get('es');
|
|
87
|
+
it('records the translated page visibility on path matches', () => {
|
|
88
|
+
expect(esMatch('/visible')).toEqual({
|
|
89
|
+
href: '/es/visible',
|
|
90
|
+
matchLevel: DivisionMatchLevel.PATH,
|
|
91
|
+
});
|
|
92
|
+
expect(esMatch('/hidden-page')).toEqual({
|
|
93
|
+
href: '/es/hidden-page',
|
|
94
|
+
matchLevel: DivisionMatchLevel.PATH,
|
|
95
|
+
hidden: true,
|
|
96
|
+
});
|
|
97
|
+
expect(esMatch('/in-hidden-group')).toEqual({
|
|
98
|
+
href: '/es/in-hidden-group',
|
|
99
|
+
matchLevel: DivisionMatchLevel.PATH,
|
|
100
|
+
hidden: true,
|
|
101
|
+
});
|
|
102
|
+
expect(esMatch('/noindexed')).toEqual({
|
|
103
|
+
href: '/es/noindexed',
|
|
104
|
+
matchLevel: DivisionMatchLevel.PATH,
|
|
105
|
+
noindex: true,
|
|
106
|
+
});
|
|
107
|
+
expect(esMatch('/gated')).toEqual({
|
|
108
|
+
href: '/es/gated',
|
|
109
|
+
matchLevel: DivisionMatchLevel.PATH,
|
|
110
|
+
groups: ['staff'],
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
});
|