Skip to content

Commit 01aacb7

Browse files
author
Sarah Edwards
authored
Merge branch 'main' into openapi-update-56c466560673b0199afcc6bfcf10a3be57ac4fc3c22e2321682ced3d5c643588
2 parents b4680af + 51a9c7b commit 01aacb7

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

lib/rewrite-local-links.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ const externalRedirects = Object.keys(require('./redirects/external-sites'))
22
const pathUtils = require('./path-utils')
33
const assert = require('assert')
44
const nonEnterpriseDefaultVersion = require('./non-enterprise-default-version')
5-
const supportedPlans = Object.values(require('./all-versions')).map(v => v.plan)
5+
const allVersions = require('./all-versions')
6+
const supportedVersions = Object.keys(allVersions)
7+
const supportedPlans = Object.values(allVersions).map(v => v.plan)
68

79
// Content authors write links like `/some/article/path`, but they need to be
810
// rewritten on the fly to match the current language and page version
@@ -27,9 +29,13 @@ function getNewHref (link, languageCode, version) {
2729

2830
let newHref
2931

30-
// If the link has a hardcoded plan name in it (e.g., /enterprise-server/rest/reference/oauth-authorizations),
31-
// only rewrite it with a language code
32-
if (supportedPlans.includes(href.split('/')[1])) {
32+
// If the link has a hardcoded plan or version in it, do not update the version, just add the language code
33+
// Examples:
34+
// /enterprise-server@2.20/rest/reference/oauth-authorizations
35+
// /enterprise-server/rest/reference/oauth-authorizations (this redirects to the latest version)
36+
// /enterprise-server@latest/rest/reference/oauth-authorizations (this redirects to the latest version)
37+
const firstLinkSegment = href.split('/')[1]
38+
if ([...supportedPlans, ...supportedVersions, 'enterprise-server@latest'].includes(firstLinkSegment)) {
3339
newHref = pathUtils.getPathWithLanguage(href, languageCode)
3440
}
3541

0 commit comments

Comments
 (0)