2021-04-15 21:16:47 +03:00
|
|
|
// 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.
|
2021-07-15 00:35:01 +03:00
|
|
|
export default function getDocumentType(relativePath) {
|
2021-04-15 21:16:47 +03:00
|
|
|
// A non-index file is ALWAYS considered an article in this approach,
|
|
|
|
// even if it's at the category level (like actions/quickstart.md)
|
2021-03-30 02:38:29 +03:00
|
|
|
if (!relativePath.endsWith('index.md')) {
|
|
|
|
return 'article'
|
|
|
|
}
|
|
|
|
|
2021-04-15 21:16:47 +03:00
|
|
|
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')
|
|
|
|
|
2021-11-18 22:20:20 +03:00
|
|
|
const publicDocs = ['homepage', 'product', 'category', 'mapTopic']
|
2021-04-15 21:16:47 +03:00
|
|
|
|
2021-11-18 22:20:20 +03:00
|
|
|
const earlyAccessDocs = ['homepage', 'early-access', 'product', 'category', 'mapTopic']
|
2021-04-15 21:16:47 +03:00
|
|
|
|
2021-11-18 22:20:20 +03:00
|
|
|
// Anything beyond the largest depth is assumed to be a mapTopic
|
|
|
|
return isEarlyAccess
|
|
|
|
? earlyAccessDocs[Math.min(segmentLength, earlyAccessDocs.length) - 1]
|
|
|
|
: publicDocs[Math.min(segmentLength, publicDocs.length) - 1]
|
2021-03-30 02:38:29 +03:00
|
|
|
}
|