(node, languageCode, version)
| 81 | } |
| 82 | |
| 83 | function getNewHref(node, languageCode, version) { |
| 84 | const { href } = node.properties |
| 85 | // Exceptions to link rewriting |
| 86 | if (href.startsWith('/assets')) return |
| 87 | if (href.startsWith('/public')) return |
| 88 | if (href in externalRedirects) return |
| 89 | |
| 90 | let newHref = href |
| 91 | // If the link has a hardcoded plan or version in it, do not update other than adding a language code |
| 92 | // Examples: |
| 93 | // /enterprise-server@2.20/rest/reference/oauth-authorizations |
| 94 | // /enterprise-server/rest/reference/oauth-authorizations (this redirects to the latest version) |
| 95 | // /enterprise-server@latest/rest/reference/oauth-authorizations (this redirects to the latest version) |
| 96 | const firstLinkSegment = href.split('/')[1] |
| 97 | if (supportedPlans.has(firstLinkSegment.split('@')[0])) { |
| 98 | newHref = path.posix.join('/', languageCode, href) |
| 99 | } |
| 100 | |
| 101 | // If the link includes a deprecated version, do not update other than adding a language code |
| 102 | // Example: /enterprise/11.10.340/admin/articles/upgrading-to-the-latest-release |
| 103 | const oldEnterpriseVersionNumber = href.match(patterns.getEnterpriseVersionNumber) |
| 104 | if (oldEnterpriseVersionNumber && deprecated.includes(oldEnterpriseVersionNumber[1])) { |
| 105 | newHref = path.posix.join('/', languageCode, href) |
| 106 | } |
| 107 | |
| 108 | // Treat the unicorn where we have version numbers. |
| 109 | // As of Jan 2022, the only plan that uses version numbers is |
| 110 | // 'enterprise-server'. But some day there might more and when that day |
| 111 | // comes this line needs to account for all those where "latest" needs |
| 112 | // to be replaced by its actual latest version number. |
| 113 | // The reason for doing this rewrite is that we want to suppress the |
| 114 | // use of '...@latest' because it's just going to redirect when viewed |
| 115 | // anyway. And if a page is archived, all "latest" is replaced to the |
| 116 | // current number anyway. |
| 117 | newHref = newHref.replace('/enterprise-server@latest/', `/enterprise-server@${latest}/`) |
| 118 | |
| 119 | if (newHref === href) { |
| 120 | // start clean with no language (TOC pages already include the lang codes via lib/liquid-tags/link.js) |
| 121 | const hrefWithoutLang = getPathWithoutLanguage(href) |
| 122 | |
| 123 | // normalize any legacy links so they conform to new link structure |
| 124 | newHref = path.posix.join('/', languageCode, getNewVersionedPath(hrefWithoutLang)) |
| 125 | |
| 126 | // get the current version from the link |
| 127 | const versionFromHref = getVersionStringFromPath(newHref) |
| 128 | |
| 129 | // ------ BEGIN ONE-OFF OVERRIDES ------// |
| 130 | // dotcom-only links always point to dotcom |
| 131 | if (node.properties.className && node.properties.className.includes('dotcom-only')) { |
| 132 | // See internal issue #2672 |
| 133 | console.warn('This is deprecated and will soon be removed') |
| 134 | version = nonEnterpriseDefaultVersion |
| 135 | } |
| 136 | |
| 137 | // desktop links always point to dotcom |
| 138 | if (patterns.desktop.test(hrefWithoutLang)) { |
| 139 | version = nonEnterpriseDefaultVersion |
| 140 | } |
no test coverage detected