Skip to content

Commit b47aaec

Browse files
committed
remove all the legacy redirect handling!
1 parent ca39571 commit b47aaec

1 file changed

Lines changed: 17 additions & 90 deletions

File tree

lib/redirects/get-old-paths-from-permalink.js

Lines changed: 17 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,124 +1,51 @@
1-
const { latest, deprecated, lastReleaseWithLegacyFormat } = require('../enterprise-server-releases')
1+
const { latest } = require('../enterprise-server-releases')
22
const { getPathWithoutLanguage, getPathWithLanguage, getVersionStringFromPath } = require('../path-utils')
3-
const patterns = require('../patterns')
4-
const versionSatisfiesRange = require('../version-satisfies-range')
53
const currentlySupportedVersions = Object.keys(require('../all-versions'))
64
const nonEnterpriseDefaultVersion = require('../non-enterprise-default-version')
75

86
// This function takes a current path, applies what we know about historically
97
// supported paths, and returns an array of ALL possible associated old
108
// paths that users might try to hit.
11-
module.exports = function getOldPathsFromPath (currentPath, languageCode, currentVersion) {
9+
module.exports = function getOldPathsFromPath (currentPath, languageCode) {
1210
const oldPaths = new Set()
1311

1412
const versionFromPath = getVersionStringFromPath(currentPath)
1513

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))) {
1917
oldPaths.add(currentPath
2018
.replace(`/${languageCode}`, `/${languageCode}/${nonEnterpriseDefaultVersion}`))
2119
}
2220

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
2821
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'))
4223

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
5025
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'))
5927

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
6129
oldPaths.add(currentPath
62-
.replace(`/enterprise/${latest}/user/`, '/enterprise/'))
30+
.replace(`/enterprise-server@${latest}/insights`, '/insights'))
6331

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'))
10135

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'))
10939

11040
// For each old path added to the set above, do the following...
111-
(new Set(oldPaths)).forEach(oldPath => {
41+
oldPaths.forEach(oldPath => {
11242
// for English only, remove language code
11343
if (languageCode === 'en') {
11444
oldPaths.add(getPathWithoutLanguage(oldPath))
11545
}
11646

11747
// add language code
11848
oldPaths.add(getPathWithLanguage(oldPath, languageCode))
119-
120-
// create /enterprise from /enterprise/latest
121-
oldPaths.add(oldPath.replace(`/enterprise/${latest}`, '/enterprise'))
12249
})
12350

12451
// exclude any empty old paths that may have been derived

0 commit comments

Comments
 (0)