@@ -2,7 +2,9 @@ const externalRedirects = Object.keys(require('./redirects/external-sites'))
22const pathUtils = require ( './path-utils' )
33const assert = require ( 'assert' )
44const 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