@mintlify/common 1.0.1345 → 1.0.1347
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/mintIgnore.js
CHANGED
|
@@ -86,7 +86,37 @@ export function isMintIgnoredBy(filePath, matcher, isDirectory = false) {
|
|
|
86
86
|
* @returns A matcher covering DEFAULT_MINT_IGNORES plus the provided patterns.
|
|
87
87
|
*/
|
|
88
88
|
export function createMintIgnoreMatcher(globs = []) {
|
|
89
|
-
|
|
89
|
+
if (globs.some((glob) => glob.startsWith('!') || /[\r\n]/.test(glob))) {
|
|
90
|
+
return ignore().add(Array.from(new Set([...DEFAULT_MINT_IGNORES, ...globs])));
|
|
91
|
+
}
|
|
92
|
+
const literalPaths = new Set();
|
|
93
|
+
const patterns = globs.filter((glob) => {
|
|
94
|
+
const relative = glob.replace(/^\//, '');
|
|
95
|
+
if ((!glob.startsWith('/') && !relative.replace(/\/$/, '').includes('/')) ||
|
|
96
|
+
!/^[a-zA-Z0-9_.-]+(?:\/[a-zA-Z0-9_.-]+)*\/?$/.test(relative) ||
|
|
97
|
+
relative.split('/').some((segment) => segment === '.' || segment === '..')) {
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
literalPaths.add(relative.toLowerCase());
|
|
101
|
+
return false;
|
|
102
|
+
});
|
|
103
|
+
const matcher = ignore().add(Array.from(new Set([...DEFAULT_MINT_IGNORES, ...patterns])));
|
|
104
|
+
if (literalPaths.size === 0)
|
|
105
|
+
return matcher;
|
|
106
|
+
return {
|
|
107
|
+
ignores(filePath) {
|
|
108
|
+
if (matcher.ignores(filePath))
|
|
109
|
+
return true;
|
|
110
|
+
const lowerPath = filePath.replace(/[A-Z]/g, (letter) => letter.toLowerCase());
|
|
111
|
+
for (let end = lowerPath.indexOf('/'); end !== -1; end = lowerPath.indexOf('/', end + 1)) {
|
|
112
|
+
if (literalPaths.has(lowerPath.slice(0, end)) ||
|
|
113
|
+
literalPaths.has(lowerPath.slice(0, end + 1))) {
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return literalPaths.has(lowerPath);
|
|
118
|
+
},
|
|
119
|
+
};
|
|
90
120
|
}
|
|
91
121
|
function normalizeMintIgnorePath(filePath) {
|
|
92
122
|
let normalized = toPosixPath(filePath);
|
|
@@ -277,7 +277,7 @@ function buildDivisionItem(param) {
|
|
|
277
277
|
let isCurrentPageMatch = false;
|
|
278
278
|
// TODO: support this for other divisions (versions, languages, etc.)
|
|
279
279
|
// check if items's subdivisions are dropdowns
|
|
280
|
-
if (dropdownCache.size && 'dropdowns' in item) {
|
|
280
|
+
if (dropdownCache.size && 'dropdowns' in item && divisionKey !== 'versions') {
|
|
281
281
|
const dropdowns = item.dropdowns;
|
|
282
282
|
const itemName = findDivisionName(item);
|
|
283
283
|
const parentContext = [...parentDivisionNames, itemName].filter(Boolean).join(':');
|
|
@@ -305,7 +305,7 @@ function buildDivisionItem(param) {
|
|
|
305
305
|
href = isUserDefinedHref ? userHref : (page === null || page === void 0 ? void 0 : page.href) || '/';
|
|
306
306
|
// when users switch languages, we should stay on the same page
|
|
307
307
|
// instead of switching to the first page in the new language
|
|
308
|
-
if (!isUserDefinedHref && divisionKey === 'languages') {
|
|
308
|
+
if (!isUserDefinedHref && (divisionKey === 'languages' || divisionKey === 'versions')) {
|
|
309
309
|
href = '';
|
|
310
310
|
}
|
|
311
311
|
}
|
|
@@ -1052,6 +1052,31 @@ describe('filterDivisions root-relative division hrefs', () => {
|
|
|
1052
1052
|
} }));
|
|
1053
1053
|
expect((_a = result.languages.find((l) => l.language === 'fr')) === null || _a === void 0 ? void 0 : _a.href).toBe('');
|
|
1054
1054
|
});
|
|
1055
|
+
it('uses a root-relative href on a version without child navigation', () => {
|
|
1056
|
+
var _a, _b;
|
|
1057
|
+
const result = filterDivisions(Object.assign(Object.assign({}, defaultArgs), { decoratedNav: {
|
|
1058
|
+
versions: [
|
|
1059
|
+
{ version: 'v2', groups: guidesGroups },
|
|
1060
|
+
{ version: 'v1', href: '/platform/v1' },
|
|
1061
|
+
],
|
|
1062
|
+
} }));
|
|
1063
|
+
expect((_a = result.versions.find((v) => v.name === 'v1')) === null || _a === void 0 ? void 0 : _a.href).toBe('/platform/v1');
|
|
1064
|
+
expect((_b = result.versions.find((v) => v.name === 'v2')) === null || _b === void 0 ? void 0 : _b.href).toBe('');
|
|
1065
|
+
});
|
|
1066
|
+
it('leaves a cached dropdown page off a version href', () => {
|
|
1067
|
+
var _a;
|
|
1068
|
+
const dropdowns = (version) => [
|
|
1069
|
+
{ dropdown: 'A', groups: [{ group: 'A', pages: [{ title: 'A', href: `/${version}/a` }] }] },
|
|
1070
|
+
{ dropdown: 'B', groups: [{ group: 'B', pages: [{ title: 'B', href: `/${version}/b` }] }] },
|
|
1071
|
+
];
|
|
1072
|
+
const result = filterDivisions(Object.assign(Object.assign({}, defaultArgs), { currentPath: '/v2/a', currentVersion: 'v2', cache: { dropdownCache: new Map([['v1:AB', '/v1/a']]) }, decoratedNav: {
|
|
1073
|
+
versions: [
|
|
1074
|
+
{ version: 'v2', dropdowns: dropdowns('v2') },
|
|
1075
|
+
{ version: 'v1', dropdowns: dropdowns('v1') },
|
|
1076
|
+
],
|
|
1077
|
+
} }));
|
|
1078
|
+
expect((_a = result.versions.find((v) => v.name === 'v1')) === null || _a === void 0 ? void 0 : _a.href).toBe('');
|
|
1079
|
+
});
|
|
1055
1080
|
it('does not treat protocol-relative hrefs as internal', () => {
|
|
1056
1081
|
var _a;
|
|
1057
1082
|
const result = filterDivisions(Object.assign(Object.assign({}, defaultArgs), { decoratedNav: {
|