File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ // This function derives the document type from the *relative path* segment length,
2+ // where a relative path refers to the content path starting with the product dir.
3+ // For example: actions/index.md or github/getting-started-with-github/quickstart.md.
14module . exports = function getDocumentType ( relativePath ) {
5+ // A non-index file is ALWAYS considered an article in this approach,
6+ // even if it's at the category level (like actions/quickstart.md)
27 if ( ! relativePath . endsWith ( 'index.md' ) ) {
38 return 'article'
49 }
510
6- // Derive the document type from the path segment length
7- switch ( relativePath . split ( '/' ) . length ) {
8- case 1 :
9- return 'homepage'
10- case 2 :
11- return 'product'
12- case 3 :
13- return 'category'
14- case 4 :
15- return 'mapTopic'
11+ const segmentLength = relativePath . split ( '/' ) . length
12+
13+ // Early Access has an extra tree segment, so it has a different number of segments.
14+ const isEarlyAccess = relativePath . startsWith ( 'early-access' )
15+
16+ const publicDocs = {
17+ 1 : 'homepage' ,
18+ 2 : 'product' ,
19+ 3 : 'category' ,
20+ 4 : 'mapTopic'
1621 }
22+
23+ const earlyAccessDocs = {
24+ 1 : 'homepage' ,
25+ 2 : 'early-access' ,
26+ 3 : 'product' ,
27+ 4 : 'category' ,
28+ 5 : 'mapTopic'
29+ }
30+
31+ return isEarlyAccess
32+ ? earlyAccessDocs [ segmentLength ]
33+ : publicDocs [ segmentLength ]
1734}
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ const slash = require('slash')
1717const statsd = require ( './statsd' )
1818const readFileContents = require ( './read-file-contents' )
1919const getLinkData = require ( './get-link-data' )
20+ const getDocumentType = require ( './get-document-type' )
2021const union = require ( 'lodash/union' )
2122
2223class Page {
@@ -76,6 +77,9 @@ class Page {
7677 this . introLinks . rawOverview = this . introLinks . overview
7778 }
7879
80+ // Is this the Homepage or a Product, Category, Topic, or Article?
81+ this . documentType = getDocumentType ( this . relativePath )
82+
7983 // Get array of versions that the page is available in for fast lookup
8084 this . applicableVersions = getApplicableVersions ( this . versions , this . fullPath )
8185
You can’t perform that action at this time.
0 commit comments