forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathis-archived-version.js
27 lines (22 loc) · 982 Bytes
/
is-archived-version.js
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
const patterns = require('../lib/patterns')
const { deprecated } = require('../lib/enterprise-server-releases')
module.exports = function isArchivedVersion (req) {
// if this is an assets path, use the referrer
// if this is a docs path, use the req.path
const pathToCheck = patterns.assetPaths.test(req.path)
? req.get('referrer')
: req.path
// ignore paths that don't have an enterprise version number
if (!(patterns.getEnterpriseVersionNumber.test(pathToCheck) || patterns.getEnterpriseServerNumber.test(pathToCheck))) {
return {}
}
// extract enterprise version from path, e.g. 2.16
const requestedVersion = pathToCheck.includes('enterprise-server@')
? pathToCheck.match(patterns.getEnterpriseServerNumber)[1]
: pathToCheck.match(patterns.getEnterpriseVersionNumber)[1]
// bail if the request version is not deprecated
if (!deprecated.includes(requestedVersion)) {
return {}
}
return { isArchived: true, requestedVersion }
}