Skip to content

Commit 7889518

Browse files
committed
updates for clarity
1 parent 51a4b9a commit 7889518

2 files changed

Lines changed: 18 additions & 8 deletions

File tree

lib/path-utils.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const slash = require('slash')
22
const path = require('path')
33
const patterns = require('./patterns')
4-
const { deprecated } = require('./enterprise-server-releases')
4+
const { deprecated, latest } = require('./enterprise-server-releases')
55
const allProducts = require('./all-products')
66
const allVersions = require('./all-versions')
77
const 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) {
8990
function 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

tests/helpers/links-checker.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,10 @@ class LinksChecker {
145145
if (gheVersionInLink && deprecated.includes(gheVersionInLink[1])) continue
146146
// ------ END ONEOFF EXCLUSIONS -------///
147147

148-
// look for linked page
148+
// the link at this point should include a version via lib/rewrite-local-links
149149
const versionFromHref = getVersionStringFromPath(link)
150+
151+
// look for linked page
150152
const linkedPage = findPageInVersion(link, context.pages, context.redirects, this.languageCode, versionFromHref)
151153
this.checkedLinksCache.add(link)
152154

0 commit comments

Comments
 (0)