Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

get-old-paths-from-permalink.js 5.3 KB

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

Press p or to see the previous file or, n or to see the next file

Comments

Loading...