Skip to content

Commit 1500186

Browse files
authored
fix: out-of-bounds depth map in getDocumentType (github#22834)
* fix: out-of-bounds depth map in getDocumentType * convert document type map to array
1 parent f500842 commit 1500186

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

lib/get-document-type.js

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,12 @@ export default function getDocumentType(relativePath) {
1313
// Early Access has an extra tree segment, so it has a different number of segments.
1414
const isEarlyAccess = relativePath.startsWith('early-access')
1515

16-
const publicDocs = {
17-
1: 'homepage',
18-
2: 'product',
19-
3: 'category',
20-
4: 'mapTopic',
21-
}
16+
const publicDocs = ['homepage', 'product', 'category', 'mapTopic']
2217

23-
const earlyAccessDocs = {
24-
1: 'homepage',
25-
2: 'early-access',
26-
3: 'product',
27-
4: 'category',
28-
5: 'mapTopic',
29-
}
18+
const earlyAccessDocs = ['homepage', 'early-access', 'product', 'category', 'mapTopic']
3019

31-
return isEarlyAccess ? earlyAccessDocs[segmentLength] : publicDocs[segmentLength]
20+
// Anything beyond the largest depth is assumed to be a mapTopic
21+
return isEarlyAccess
22+
? earlyAccessDocs[Math.min(segmentLength, earlyAccessDocs.length) - 1]
23+
: publicDocs[Math.min(segmentLength, publicDocs.length) - 1]
3224
}

0 commit comments

Comments
 (0)