Skip to content

Commit 51a9c7b

Browse files
authored
Merge pull request #16853 from github/support-hardcoded-version-or-plan-in-link
Support hardcoded versions in links in multiple formats
2 parents acce63e + 6ada81f commit 51a9c7b

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)