forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get-document-type.js
32 lines (27 loc) · 1.02 KB
/
get-document-type.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// This function derives the document type from the *relative path* segment length,
// where a relative path refers to the content path starting with the product dir.
// For example: actions/index.md or github/getting-started-with-github/quickstart.md.
export default function getDocumentType(relativePath) {
// A non-index file is ALWAYS considered an article in this approach,
// even if it's at the category level (like actions/quickstart.md)
if (!relativePath.endsWith('index.md')) {
return 'article'
}
const segmentLength = relativePath.split('/').length
// Early Access has an extra tree segment, so it has a different number of segments.
const isEarlyAccess = relativePath.startsWith('early-access')
const publicDocs = {
1: 'homepage',
2: 'product',
3: 'category',
4: 'mapTopic',
}
const earlyAccessDocs = {
1: 'homepage',
2: 'early-access',
3: 'product',
4: 'category',
5: 'mapTopic',
}
return isEarlyAccess ? earlyAccessDocs[segmentLength] : publicDocs[segmentLength]
}