Instruct search engines to not crawl archived versions (#16292)

* Instruct search engines to not crawl archived versions

* Update middleware/robots.js

Co-authored-by: Sarah Schneider <sarahs@users.noreply.github.com>

* Add test

* Fix spooky bug

Co-authored-by: Chiedo <chiedo@users.noreply.github.com>
Co-authored-by: Sarah Schneider <sarahs@users.noreply.github.com>
This commit is contained in:
Chiedo John 2020-11-03 08:23:22 -05:00 коммит произвёл GitHub
Родитель 23732ffe46
Коммит 7924aea2f8
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 30 добавлений и 0 удалений

Просмотреть файл

@ -1,5 +1,6 @@
const languages = require('../lib/languages')
const products = require('../lib/all-products')
const { deprecated } = require('../lib/enterprise-server-releases.js')
let defaultResponse = 'User-agent: *'
@ -34,5 +35,13 @@ module.exports = function (req, res, next) {
defaultResponse = defaultResponse.concat(`\nDisallow: /*${product.href}\nDisallow: /*/enterprise/*/user${product.href}`)
})
// Disallow crawling of Deprecated enterprise versions
deprecated
.forEach(version => {
defaultResponse = defaultResponse
.concat(`\nDisallow: /*/enterprise-server@${version}/*`)
.concat(`\nDisallow: /*/enterprise/${version}/*`)
})
return res.send(defaultResponse)
}

Просмотреть файл

@ -89,4 +89,25 @@ describe('robots.txt', () => {
expect(robots.isAllowed(`https://help.github.com/en/enterprise/${enterpriseServerReleases.latest}/user/actions`)).toBe(true)
expect(robots.isAllowed(`https://help.github.com/en/enterprise/${enterpriseServerReleases.oldestSupported}/user/actions`)).toBe(true)
})
it('disallows indexing of deprecated enterprise releases', async () => {
enterpriseServerReleases.deprecated.forEach(version => {
const blockedPaths = [
// English
`https://help.github.com/en/enterprise-server@${version}/actions`,
`https://help.github.com/en/enterprise/${version}/actions`,
`https://help.github.com/en/enterprise-server@${version}/actions/overview`,
`https://help.github.com/en/enterprise/${version}/actions/overview`,
// Japanese
`https://help.github.com/ja/enterprise-server@${version}/actions`,
`https://help.github.com/ja/enterprise/${version}/actions`,
`https://help.github.com/ja/enterprise-server@${version}/actions/overview`,
`https://help.github.com/ja/enterprise/${version}/actions/overview`
]
blockedPaths.forEach(path => {
expect(robots.isAllowed(path)).toBe(false)
})
})
})
})