-
Notifications
You must be signed in to change notification settings - Fork 61.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16853 from github/support-hardcoded-version-or-pl…
…an-in-link Support hardcoded versions in links in multiple formats
- Loading branch information
Showing
1 changed file
with
10 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,9 @@ const externalRedirects = Object.keys(require('./redirects/external-sites')) | |
const pathUtils = require('./path-utils') | ||
const assert = require('assert') | ||
const nonEnterpriseDefaultVersion = require('./non-enterprise-default-version') | ||
const supportedPlans = Object.values(require('./all-versions')).map(v => v.plan) | ||
const allVersions = require('./all-versions') | ||
const supportedVersions = Object.keys(allVersions) | ||
const supportedPlans = Object.values(allVersions).map(v => v.plan) | ||
|
||
// Content authors write links like `/some/article/path`, but they need to be | ||
// rewritten on the fly to match the current language and page version | ||
|
@@ -27,9 +29,13 @@ function getNewHref (link, languageCode, version) { | |
|
||
let newHref | ||
|
||
// If the link has a hardcoded plan name in it (e.g., /enterprise-server/rest/reference/oauth-authorizations), | ||
// only rewrite it with a language code | ||
if (supportedPlans.includes(href.split('/')[1])) { | ||
// If the link has a hardcoded plan or version in it, do not update the version, just add the language code | ||
// Examples: | ||
// /[email protected]/rest/reference/oauth-authorizations | ||
// /enterprise-server/rest/reference/oauth-authorizations (this redirects to the latest version) | ||
// /enterprise-server@latest/rest/reference/oauth-authorizations (this redirects to the latest version) | ||
const firstLinkSegment = href.split('/')[1] | ||
if ([...supportedPlans, ...supportedVersions, 'enterprise-server@latest'].includes(firstLinkSegment)) { | ||
newHref = pathUtils.getPathWithLanguage(href, languageCode) | ||
} | ||
|
||
|