diff --git a/lib/get-document-type.js b/lib/get-document-type.js index 8c3fab956e..11cebd7ca2 100644 --- a/lib/get-document-type.js +++ b/lib/get-document-type.js @@ -1,17 +1,34 @@ +// 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. module.exports = 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' } - // Derive the document type from the path segment length - switch (relativePath.split('/').length) { - case 1: - return 'homepage' - case 2: - return 'product' - case 3: - return 'category' - case 4: - return 'mapTopic' + 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] } diff --git a/lib/page.js b/lib/page.js index 1254b83b73..66939414d7 100644 --- a/lib/page.js +++ b/lib/page.js @@ -17,6 +17,7 @@ const slash = require('slash') const statsd = require('./statsd') const readFileContents = require('./read-file-contents') const getLinkData = require('./get-link-data') +const getDocumentType = require('./get-document-type') const union = require('lodash/union') class Page { @@ -76,6 +77,9 @@ class Page { this.introLinks.rawOverview = this.introLinks.overview } + // Is this the Homepage or a Product, Category, Topic, or Article? + this.documentType = getDocumentType(this.relativePath) + // Get array of versions that the page is available in for fast lookup this.applicableVersions = getApplicableVersions(this.versions, this.fullPath)