@@ -4,7 +4,7 @@ const externalRedirects = Object.keys(require('./redirects/external-sites'))
44const { getPathWithoutLanguage, getVersionStringFromPath } = require ( './path-utils' )
55const { getNewVersionedPath } = require ( './old-versions-utils' )
66const patterns = require ( './patterns' )
7- const { latest } = require ( './enterprise-server-releases' )
7+ const { deprecated , latest } = require ( './enterprise-server-releases' )
88const nonEnterpriseDefaultVersion = require ( './non-enterprise-default-version' )
99const removeFPTFromPath = require ( './remove-fpt-from-path' )
1010const allVersions = require ( './all-versions' )
@@ -24,16 +24,13 @@ module.exports = function rewriteLocalLinks ($, version, languageCode) {
2424function getNewHref ( link , languageCode , version ) {
2525 const href = link . attr ( 'href' )
2626
27- // these links should not be rewritten
27+ // Exceptions to link rewriting
2828 if ( href . startsWith ( '/assets' ) ) return
2929 if ( href . startsWith ( '/public' ) ) return
30-
31- // Leave old redirected URLs intact
32- // e.g. `/contact` should not be replaced with `/en/contact`
3330 if ( externalRedirects . includes ( href ) ) return
3431
35- let newHref
36- // If the link has a hardcoded plan or version in it, do not update the version, just add the language code
32+ let newHref = href
33+ // If the link has a hardcoded plan or version in it, do not update other than adding a language code
3734 // Examples:
3835 // /enterprise-server@2.20/rest/reference/oauth-authorizations
3936 // /enterprise-server/rest/reference/oauth-authorizations (this redirects to the latest version)
@@ -43,11 +40,16 @@ function getNewHref (link, languageCode, version) {
4340 newHref = path . join ( '/' , languageCode , href )
4441 }
4542
46- // If link is dotcom-only, just get the language code
47- // Otherwise, get the versioned path with language code
48- if ( ! newHref ) {
43+ // If the link includes a deprecated version, do not update other than adding a language code
44+ // Example: /enterprise/11.10.340/admin/articles/upgrading-to-the-latest-release
45+ const oldEnterpriseVersionNumber = href . match ( patterns . getEnterpriseVersionNumber )
46+ if ( oldEnterpriseVersionNumber && deprecated . includes ( oldEnterpriseVersionNumber [ 1 ] ) ) {
47+ newHref = path . join ( '/' , languageCode , href )
48+ }
49+
50+ if ( newHref === href ) {
4951 // start clean with no language (TOC pages already include the lang codes via lib/liquid-tags/link.js)
50- const hrefWithoutLang = getPathWithoutLanguage ( href ) . replace ( patterns . trailingSlash , '$1' )
52+ const hrefWithoutLang = getPathWithoutLanguage ( href )
5153
5254 // normalize any legacy links so they conform to new link structure
5355 newHref = path . join ( '/' , languageCode , getNewVersionedPath ( hrefWithoutLang ) )
@@ -76,5 +78,7 @@ function getNewHref (link, languageCode, version) {
7678 newHref = removeFPTFromPath ( newHref . replace ( versionFromHref , version ) )
7779 }
7880
81+ newHref = newHref . replace ( patterns . trailingSlash , '$1' )
82+
7983 if ( href !== newHref ) link . attr ( 'href' , newHref )
8084}
0 commit comments