|
1 | | -const { latest, deprecated, lastReleaseWithLegacyFormat } = require('../enterprise-server-releases') |
| 1 | +const { latest } = require('../enterprise-server-releases') |
2 | 2 | const { getPathWithoutLanguage, getPathWithLanguage, getVersionStringFromPath } = require('../path-utils') |
3 | | -const patterns = require('../patterns') |
4 | | -const versionSatisfiesRange = require('../version-satisfies-range') |
5 | 3 | const currentlySupportedVersions = Object.keys(require('../all-versions')) |
6 | 4 | const nonEnterpriseDefaultVersion = require('../non-enterprise-default-version') |
7 | 5 |
|
8 | 6 | // This function takes a current path, applies what we know about historically |
9 | 7 | // supported paths, and returns an array of ALL possible associated old |
10 | 8 | // paths that users might try to hit. |
11 | | -module.exports = function getOldPathsFromPath (currentPath, languageCode, currentVersion) { |
| 9 | +module.exports = function getOldPathsFromPath (currentPath, languageCode) { |
12 | 10 | const oldPaths = new Set() |
13 | 11 |
|
14 | 12 | const versionFromPath = getVersionStringFromPath(currentPath) |
15 | 13 |
|
16 | | - // This only applies to Dotcom paths, so no need to determine whether the version is deprecated |
17 | | - // create old path /free-pro-team@latest/github from new path /github (or from a frontmatter `redirect_from` path like /articles) |
18 | | - if (versionFromPath === 'homepage' || !(currentlySupportedVersions.includes(versionFromPath) || deprecated.includes(versionFromPath)) || (versionFromPath === nonEnterpriseDefaultVersion && !currentPath.includes(nonEnterpriseDefaultVersion))) { |
| 14 | + // The following only applies to Dotcom paths. |
| 15 | + // Create old path /free-pro-team@latest/github from new path /github (or from a frontmatter `redirect_from` path like /articles) |
| 16 | + if (versionFromPath === 'homepage' || !currentlySupportedVersions.includes(versionFromPath) || (versionFromPath === nonEnterpriseDefaultVersion && !currentPath.includes(nonEnterpriseDefaultVersion))) { |
19 | 17 | oldPaths.add(currentPath |
20 | 18 | .replace(`/${languageCode}`, `/${languageCode}/${nonEnterpriseDefaultVersion}`)) |
21 | 19 | } |
22 | 20 |
|
23 | | - // ------ BEGIN LEGACY VERSION FORMAT REPLACEMENTS ------// |
24 | | - // These remain relevant to handle legacy-formatted frontmatter redirects |
25 | | - // and archived versions paths. |
26 | | - |
27 | | - // create old path /insights from current path /enterprise/version/insights |
28 | 21 | oldPaths.add(currentPath |
29 | | - .replace(`/${languageCode}/enterprise/${latest}/user/insights`, '/insights')) |
30 | | - |
31 | | - // create old path /desktop/guides from current path /desktop |
32 | | - if (!currentPath.includes('/guides')) { |
33 | | - oldPaths.add(currentPath |
34 | | - .replace('/desktop', '/desktop/guides')) |
35 | | - } |
36 | | - |
37 | | - // create old path /admin/guides from current path /admin |
38 | | - if (!currentPath.includes('/guides')) { |
39 | | - oldPaths.add(currentPath |
40 | | - .replace('/admin', '/admin/guides')) |
41 | | - } |
| 22 | + .replace(/\/enterprise-server@(\d)/, '/enterprise/$1')) |
42 | 23 |
|
43 | | - // create old path /user from current path /user/github on 2.16+ only |
44 | | - if (currentlySupportedVersions.includes(currentVersion) || versionSatisfiesRange(currentVersion, '>2.15')) { |
45 | | - oldPaths.add(currentPath |
46 | | - .replace('/user/github', '/user')) |
47 | | - } |
48 | | - |
49 | | - // create old path /enterprise from current path /enterprise/latest |
| 24 | + // create old path /enterprise/<version>/user from new path /enterprise-server@<version>/github |
50 | 25 | oldPaths.add(currentPath |
51 | | - .replace(`/enterprise/${latest}`, '/enterprise')) |
52 | | - |
53 | | - // create old path /enterprise/foo from current path /enterprise/user/foo |
54 | | - // this supports old developer paths like /enterprise/webhooks with no /user in them |
55 | | - if (currentPath.includes('/enterprise/')) { |
56 | | - oldPaths.add(currentPath |
57 | | - .replace('/user/', '/')) |
58 | | - } |
| 26 | + .replace(/\/enterprise-server@(\d.+?)\/github/, '/enterprise/$1/user')) |
59 | 27 |
|
60 | | - // create old path /enterprise/foo from current path /enterprise/latest/user/foo |
| 28 | + // create old path /insights from new path /enterprise-server@<latest>/insights |
61 | 29 | oldPaths.add(currentPath |
62 | | - .replace(`/enterprise/${latest}/user/`, '/enterprise/')) |
| 30 | + .replace(`/enterprise-server@${latest}/insights`, '/insights')) |
63 | 31 |
|
64 | | - // ------ END LEGACY VERSION FORMAT REPLACEMENTS ------// |
65 | | - |
66 | | - // ------ BEGIN MODERN VERSION FORMAT REPLACEMENTS ------// |
67 | | - if (currentlySupportedVersions.includes(currentVersion) || versionSatisfiesRange(currentVersion, `>${lastReleaseWithLegacyFormat}`)) { |
68 | | - (new Set(oldPaths)).forEach(oldPath => { |
69 | | - // create old path /enterprise/<version> from new path /enterprise-server@<version> |
70 | | - oldPaths.add(oldPath |
71 | | - .replace(/\/enterprise-server@(\d)/, '/enterprise/$1')) |
72 | | - |
73 | | - // create old path /enterprise/<version>/user from new path /enterprise-server@<version>/github |
74 | | - oldPaths.add(oldPath |
75 | | - .replace(/\/enterprise-server@(\d.+?)\/github/, '/enterprise/$1/user')) |
76 | | - |
77 | | - // create old path /insights from new path /enterprise-server@<latest>/insights |
78 | | - oldPaths.add(oldPath |
79 | | - .replace(`/enterprise-server@${latest}/insights`, '/insights')) |
80 | | - |
81 | | - // create old path /admin from new path /enterprise-server@<latest>/admin |
82 | | - oldPaths.add(oldPath |
83 | | - .replace(`/enterprise-server@${latest}/admin`, '/admin')) |
84 | | - |
85 | | - // create old path /enterprise from new path /enterprise-server@<latest> |
86 | | - oldPaths.add(oldPath |
87 | | - .replace(`/enterprise-server@${latest}`, '/enterprise')) |
88 | | - |
89 | | - // create old path /enterprise-server from new path /enterprise-server@<latest> |
90 | | - oldPaths.add(oldPath |
91 | | - .replace(`/enterprise-server@${latest}`, '/enterprise-server')) |
92 | | - |
93 | | - // create old path /enterprise-server@latest from new path /enterprise-server@<latest> |
94 | | - oldPaths.add(oldPath |
95 | | - .replace(`/enterprise-server@${latest}`, '/enterprise-server@latest')) |
96 | | - |
97 | | - if (!patterns.adminProduct.test(oldPath)) { |
98 | | - // create old path /enterprise/<version>/user/foo from new path /enterprise-server@<version>/foo |
99 | | - oldPaths.add(currentPath |
100 | | - .replace(/\/enterprise-server@(\d.+?)\//, '/enterprise/$1/user/')) |
| 32 | + // create old path /admin from new path /enterprise-server@<latest>/admin |
| 33 | + oldPaths.add(currentPath |
| 34 | + .replace(`/enterprise-server@${latest}/admin`, '/admin')) |
101 | 35 |
|
102 | | - // create old path /enterprise/user/foo from new path /enterprise-server@<latest>/foo |
103 | | - oldPaths.add(currentPath |
104 | | - .replace(`/enterprise-server@${latest}/`, '/enterprise/user/')) |
105 | | - } |
106 | | - }) |
107 | | - } |
108 | | - // ------ END MODERN VERSION FORMAT REPLACEMENTS ------// |
| 36 | + // create old path /enterprise from new path /enterprise-server@<latest> |
| 37 | + oldPaths.add(currentPath |
| 38 | + .replace(`/enterprise-server@${latest}`, '/enterprise')) |
109 | 39 |
|
110 | 40 | // For each old path added to the set above, do the following... |
111 | | - (new Set(oldPaths)).forEach(oldPath => { |
| 41 | + oldPaths.forEach(oldPath => { |
112 | 42 | // for English only, remove language code |
113 | 43 | if (languageCode === 'en') { |
114 | 44 | oldPaths.add(getPathWithoutLanguage(oldPath)) |
115 | 45 | } |
116 | 46 |
|
117 | 47 | // add language code |
118 | 48 | oldPaths.add(getPathWithLanguage(oldPath, languageCode)) |
119 | | - |
120 | | - // create /enterprise from /enterprise/latest |
121 | | - oldPaths.add(oldPath.replace(`/enterprise/${latest}`, '/enterprise')) |
122 | 49 | }) |
123 | 50 |
|
124 | 51 | // exclude any empty old paths that may have been derived |
|
0 commit comments