11const slash = require ( 'slash' )
22const path = require ( 'path' )
33const patterns = require ( './patterns' )
4- const { deprecated } = require ( './enterprise-server-releases' )
4+ const { deprecated, latest } = require ( './enterprise-server-releases' )
55const allProducts = require ( './all-products' )
66const allVersions = require ( './all-versions' )
77const supportedVersions = new Set ( Object . keys ( allVersions ) )
@@ -23,7 +23,7 @@ function getVersionedPathWithoutLanguage (href, version) {
2323 // example: enterprise-server@2.22 or free-pro-team@latest
2424 let versionFromPath = getVersionStringFromPath ( href )
2525
26- // update the path with the full version so we can go through the rest of the checks
26+ // if a real version was found, add it to the path so we can go through the rest of the checks
2727 if ( supportedVersions . has ( versionFromPath ) ) {
2828 href = href . replace ( href . split ( '/' ) [ 1 ] , versionFromPath )
2929 }
@@ -36,6 +36,7 @@ function getVersionedPathWithoutLanguage (href, version) {
3636 productObjectFromPath = allProducts [ versionFromPath ]
3737
3838 // if so, add the first supported version for that product to the href
39+ // (this is just to get a path with all the expected segments; the version will be updated later if needed)
3940 if ( productObjectFromPath ) {
4041 href = path . join ( '/' , productObjectFromPath . versions [ 0 ] , href )
4142 versionFromPath = productObjectFromPath . versions [ 0 ]
@@ -89,25 +90,32 @@ function getPathWithoutVersion (href) {
8990function getVersionStringFromPath ( href ) {
9091 href = getPathWithoutLanguage ( href )
9192
93+ // return immediately if this is a link to the homepage
94+ if ( href === '/' ) {
95+ return 'homepage'
96+ }
97+
98+ // check if the first segment is a supported version
9299 const versionFromPath = href . split ( '/' ) [ 1 ]
93100
94- if ( allVersions [ versionFromPath ] ) {
101+ if ( supportedVersions . has ( versionFromPath ) ) {
95102 return versionFromPath
96103 }
97104
98105 // if the version segment is the latest enterprise-server release, return the latest release
99106 if ( versionFromPath === 'enterprise-server@latest' ) {
100- const enterpriseServerObject = Object . values ( allVersions ) . find ( v => v . plan === 'enterprise-server' )
101- return allVersions [ enterpriseServerObject . latestVersion ] . version
107+ return `enterprise-server@${ latest } `
102108 }
103109
104- // if it's just a plan with no @release, find the plan's latest release
110+ // if it's just a plan with no @release (e.g., `enterprise-server`), return the latest release
105111 const planObject = Object . values ( allVersions ) . find ( v => v . plan === versionFromPath )
106112 if ( planObject ) {
107113 return allVersions [ planObject . latestVersion ] . version
108114 }
109115
110- return versionFromPath || 'homepage'
116+ // otherwise, return the first segment as-is, which may not be a proper version
117+ // but additional checks are done on this segment in getVersionedPathWithoutLanguage
118+ return versionFromPath
111119}
112120
113121// Return the corresponding object for the version segment in a path
0 commit comments