forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblock-robots.js
37 lines (30 loc) · 1.17 KB
/
block-robots.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
28
29
30
31
32
33
34
35
36
37
import languages from '../lib/languages.js'
import { productMap } from '../lib/all-products.js'
import { deprecated } from '../lib/enterprise-server-releases.js'
const pathRegExps = [
// Disallow indexing of WIP localized content
...Object.values(languages)
.filter((language) => language.wip)
.map((language) => new RegExp(`^/${language.code}(/.*)?$`, 'i')),
// Disallow indexing of WIP products
...Object.values(productMap)
.filter((product) => product.wip || product.hidden)
.map((product) => [
new RegExp(`^/.*?${product.href}`, 'i'),
...product.versions.map((version) => new RegExp(`^/.*?${version}/${product.id}`, 'i')),
]),
// Disallow indexing of deprecated enterprise versions
...deprecated.map((version) => [
new RegExp(`^/.*?/enterprise-server@${version}/.*?`, 'i'),
new RegExp(`^/.*?/enterprise/${version}/.*?`, 'i'),
]),
].flat()
export function blockIndex(path) {
return pathRegExps.some((pathRe) => pathRe.test(path))
}
const middleware = function blockRobots(req, res, next) {
if (blockIndex(req.path)) res.set('x-robots-tag', 'noindex')
return next()
}
middleware.blockIndex = blockIndex
export default middleware