@mintlify/common 1.0.1024 → 1.0.1025

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.
@@ -10,6 +10,7 @@ export var DivisionMatchLevel;
10
10
  DivisionMatchLevel[DivisionMatchLevel["GROUP"] = 2] = "GROUP";
11
11
  DivisionMatchLevel[DivisionMatchLevel["DIVISION"] = 3] = "DIVISION";
12
12
  DivisionMatchLevel[DivisionMatchLevel["NONE"] = 4] = "NONE";
13
+ DivisionMatchLevel[DivisionMatchLevel["UNVERSIONED"] = 5] = "UNVERSIONED";
13
14
  })(DivisionMatchLevel || (DivisionMatchLevel = {}));
14
15
  const ACCEPTED_BASE_PATHS = ['docs', 'doc', 'documentation', 'help'];
15
16
  export function updateFirstHrefInDivision({ type, currentPath, entry, parentGroups, nearestDivisionValue, isActiveGroup, inActiveDivision, currentDivisionValue, allDivisionValues, firstHrefInDivision, navigationDivisions, isHiddenPage, activeGroupNames, }) {
@@ -297,9 +298,13 @@ function maybeUpdateFirstHrefInDivision(type, href, finalVersion, inActiveGroup,
297
298
  }
298
299
  return;
299
300
  }
301
+ // a page that belongs to the target division beats a division-less catch-all,
302
+ // so rule 3 ("first page in the new version") holds regardless of walk order
303
+ const fallbackLevel = finalVersion !== undefined ? DivisionMatchLevel.NONE : DivisionMatchLevel.UNVERSIONED;
300
304
  for (const version of versionsToUpdate) {
301
- if (!firstHrefInDivision.has(version)) {
302
- firstHrefInDivision.set(version, { href, matchLevel: DivisionMatchLevel.NONE });
305
+ const existingHref = firstHrefInDivision.get(version);
306
+ if (existingHref === undefined || fallbackLevel < existingHref.matchLevel) {
307
+ firstHrefInDivision.set(version, { href, matchLevel: fallbackLevel });
303
308
  }
304
309
  }
305
310
  }
@@ -0,0 +1,52 @@
1
+ import { DivisionMatchLevel, updateFirstHrefInDivision, } from './updateFirstHrefInDivision.js';
2
+ const emptyDivisions = {
3
+ tabs: [],
4
+ anchors: [],
5
+ versions: [],
6
+ languages: [],
7
+ dropdowns: [],
8
+ products: [],
9
+ menu: [],
10
+ };
11
+ function visit(firstHrefInDivision, href, nearestDivisionValue) {
12
+ const page = { title: href, href };
13
+ updateFirstHrefInDivision({
14
+ type: 'version',
15
+ currentPath: '/docs',
16
+ entry: page,
17
+ parentGroups: [],
18
+ nearestDivisionValue,
19
+ isActiveGroup: false,
20
+ inActiveDivision: false,
21
+ currentDivisionValue: undefined,
22
+ allDivisionValues: ['v2', 'v1'],
23
+ firstHrefInDivision,
24
+ navigationDivisions: emptyDivisions,
25
+ isHiddenPage: false,
26
+ });
27
+ }
28
+ describe(updateFirstHrefInDivision, () => {
29
+ it('prefers a division-owned page over an earlier unversioned catch-all', () => {
30
+ const map = new Map();
31
+ visit(map, '/docs/getting-started', undefined);
32
+ visit(map, '/docs/v1/overview', 'v1');
33
+ expect(map.get('v1')).toEqual({
34
+ href: '/docs/v1/overview',
35
+ matchLevel: DivisionMatchLevel.NONE,
36
+ });
37
+ expect(map.get('v2')).toEqual({
38
+ href: '/docs/getting-started',
39
+ matchLevel: DivisionMatchLevel.UNVERSIONED,
40
+ });
41
+ });
42
+ it('keeps the first division-owned page regardless of visit order', () => {
43
+ const map = new Map();
44
+ visit(map, '/docs/v1/overview', 'v1');
45
+ visit(map, '/docs/getting-started', undefined);
46
+ visit(map, '/docs/v1/later-page', 'v1');
47
+ expect(map.get('v1')).toEqual({
48
+ href: '/docs/v1/overview',
49
+ matchLevel: DivisionMatchLevel.NONE,
50
+ });
51
+ });
52
+ });