Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

block-robots.js 1.2 KB

You have to be logged in to leave a comment. Sign In
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
  1. const languages = require('../lib/languages')
  2. const { productMap } = require('../lib/all-products')
  3. const { deprecated } = require('../lib/enterprise-server-releases.js')
  4. const pathRegExps = [
  5. // Disallow indexing of WIP localized content
  6. ...Object.values(languages)
  7. .filter(language => language.wip)
  8. .map(language => new RegExp(`^/${language.code}(/.*)?$`, 'i')),
  9. // Disallow indexing of WIP products
  10. ...Object.values(productMap)
  11. .filter(product => product.wip || product.hidden)
  12. .map(product => [
  13. new RegExp(`^/.*?${product.href}`, 'i'),
  14. ...product.versions.map(
  15. version => new RegExp(`^/.*?${version}/${product.id}`, 'i')
  16. )
  17. ]),
  18. // Disallow indexing of deprecated enterprise versions
  19. ...deprecated
  20. .map(version => [
  21. new RegExp(`^/.*?/enterprise-server@${version}/.*?`, 'i'),
  22. new RegExp(`^/.*?/enterprise/${version}/.*?`, 'i')
  23. ])
  24. ].flat()
  25. function blockIndex (path) {
  26. return pathRegExps.some(pathRe => pathRe.test(path))
  27. }
  28. const middleware = function blockRobots (req, res, next) {
  29. if (blockIndex(req.path)) res.set('x-robots-tag', 'noindex')
  30. return next()
  31. }
  32. middleware.blockIndex = blockIndex
  33. module.exports = middleware
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...