Skip to content

Commit 3ff1bfc

Browse files
committed
account for early access
1 parent c9d0e95 commit 3ff1bfc

2 files changed

Lines changed: 17 additions & 6 deletions

File tree

lib/path-utils.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,13 @@ function getProductStringFromPath (href) {
7676

7777
if (href === '/') return 'homepage'
7878

79-
return allProducts[href.split('/')[2]]
80-
? href.split('/')[2]
81-
: href.split('/')[1]
79+
const pathParts = href.split('/')
80+
81+
if (pathParts.includes('early-access')) return 'early-access'
82+
83+
return allProducts[pathParts[2]]
84+
? pathParts[2]
85+
: pathParts[1]
8286
}
8387

8488
// Return the corresponding object for the product segment in a path

middleware/early-access-breadcrumbs.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
const path = require('path')
22
const { getPathWithoutLanguage } = require('../lib/path-utils')
3+
const nonEnterpriseDefaultVersion = require('../lib/non-enterprise-default-version')
4+
const removeFPTFromPath = require('../lib/remove-fpt-from-path')
35

46
// Early Access content doesn't conform to the same structure as other products, so we
57
// can't derive breadcrumbs from the siteTree in the same way. Hence, this separate middleware.
@@ -22,8 +24,13 @@ module.exports = async (req, res, next) => {
2224
// drop first '/'
2325
pathParts.shift()
2426

25-
// drop the version and early-accesss segments so pathParts now starts with /product
26-
pathParts.shift()
27+
// if this is not FPT, drop the version segment
28+
// if this is FPT, there is no version segment
29+
if (req.context.currentVersion !== nonEnterpriseDefaultVersion) {
30+
pathParts.shift()
31+
}
32+
33+
// drop the early-accesss segments so pathParts now starts with /product
2734
pathParts.shift()
2835

2936
// Early Access products do not require an index.md, so look for a matching public product
@@ -40,7 +47,7 @@ module.exports = async (req, res, next) => {
4047

4148
// get Early Access category path
4249
// e.g., `enforcing-best-practices-with-github-policies` in /free-pro-team@latest/early-access/github/enforcing-best-practices-with-github-policies
43-
const categoryPath = path.posix.join('/', 'en', req.context.currentVersion, 'early-access', pathParts[0], pathParts[1])
50+
const categoryPath = removeFPTFromPath(path.posix.join('/', 'en', req.context.currentVersion, 'early-access', pathParts[0], pathParts[1]))
4451
const category = req.context.pages[categoryPath]
4552

4653
if (!category) return next()

0 commit comments

Comments
 (0)