forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblock-robots.js
More file actions
81 lines (70 loc) · 2.69 KB
/
block-robots.js
File metadata and controls
81 lines (70 loc) · 2.69 KB
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
import { blockIndex } from '../../middleware/block-robots.js'
import { productMap } from '../../lib/all-products.js'
import enterpriseServerReleases from '../../lib/enterprise-server-releases.js'
function allowIndex(path) {
return !blockIndex(path)
}
describe('block robots', () => {
it('allows crawling of the homepage and English content', async () => {
expect(allowIndex('/')).toBe(true)
expect(allowIndex('/en')).toBe(true)
expect(allowIndex('/en/articles/verifying-your-email-address')).toBe(true)
})
it('disallows crawling of WIP products', async () => {
const wipProductIds = Object.values(productMap)
.filter((product) => product.wip)
.map((product) => product.id)
wipProductIds.forEach((id) => {
const { href } = productMap[id]
const blockedPaths = [
`/en${href}`,
`/en${href}/overview`,
`/en${href}/overview/intro`,
`/en/enterprise/${enterpriseServerReleases.latest}/user${href}`,
`/en/enterprise/${enterpriseServerReleases.oldestSupported}/user${href}`,
]
blockedPaths.forEach((path) => {
expect(allowIndex(path)).toBe(false)
})
})
})
it('disallows crawling of early access "hidden" products', async () => {
const hiddenProductIds = Object.values(productMap)
.filter((product) => product.hidden)
.map((product) => product.id)
hiddenProductIds.forEach((id) => {
const { versions } = productMap[id]
const blockedPaths = versions
.map((version) => {
return [`/en/${version}/${id}`, `/en/${version}/${id}/some-early-access-article`]
})
.flat()
blockedPaths.forEach((path) => {
expect(allowIndex(path)).toBe(false)
})
})
})
it('allows crawling of non-WIP products', async () => {
expect('actions' in productMap).toBe(true)
expect(allowIndex('/en/actions')).toBe(true)
expect(allowIndex('/en/actions/overview')).toBe(true)
expect(allowIndex('/en/actions/overview/intro')).toBe(true)
expect(allowIndex(`/en/enterprise/${enterpriseServerReleases.latest}/user/actions`)).toBe(true)
expect(
allowIndex(`/en/enterprise/${enterpriseServerReleases.oldestSupported}/user/actions`)
).toBe(true)
})
it('disallows crawling of deprecated enterprise releases', async () => {
enterpriseServerReleases.deprecated.forEach((version) => {
const blockedPaths = [
`/en/enterprise-server@${version}/actions`,
`/en/enterprise/${version}/actions`,
`/en/enterprise-server@${version}/actions/overview`,
`/en/enterprise/${version}/actions/overview`,
]
blockedPaths.forEach((path) => {
expect(allowIndex(path)).toBe(false)
})
})
})
})